Print Page | Close Window

Conditional formatting

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=18587
Printed Date: 29 Apr 2024 at 9:49am


Topic: Conditional formatting
Posted By: db3712
Subject: Conditional formatting
Date Posted: 15 Jan 2013 at 6:18am
Hello,
I'm new to conditional formatting and would appreciate any help.  I have a two fields.  One is a number field and the other is a formula which is essentially a summary of two other number fields.  I would like to highlight one or both of the fields if they don't match.  Can you do conditional formatting on a summary field?
 
Thanks!



Replies:
Posted By: lockwelle
Date Posted: 15 Jan 2013 at 6:34am
well, if you add a section to the group footer, and set your summarized value to a shared (or global) variable, then when you actually display the values, you can tap into your shared variables and use them to change the background color.
 
another way of saying the same thing.  find the values that you want to compare. store them in shared variables in a section above the displayed value, then access the variables to change the color.
 
example
gf1a:
shared numbervar col1 := {table.field1};
shared numbervar col2 := {table.field2};
""  //will suppress any display of the values (though you can also suppress the section
 
gf1b, {table.field1}, format object, font (i think) color, check the background(ithink)
shared numbervar col1;
shared numbervar col2;
if col1 <> col2 then
  crRed
else
  crWhite;
 
HTH


Posted By: db3712
Date Posted: 15 Jan 2013 at 7:28am
I don't completely understand.  I apologize.  It appears you want me to create two additional group footers.  Are you indicating I need to create a formula with the first gf1a above and then place a conditional format on the first formula?   I appreciate your help.


Posted By: DBlank
Date Posted: 15 Jan 2013 at 8:16am
before you move to far, you should clarify if your "summary of two fields" is adding across rows or just adding two fields on the same row. Lockwelles suggestion is a way to handle adding multiple values across rows together


Posted By: db3712
Date Posted: 15 Jan 2013 at 8:29am
Both fields are located in the same group footer.  One is a field straight from database.  The other is a summary of the following formula....
 
if isNull ({orders.is_vendor_flat_rate}) then {demand.total_cost}
else if {orders.is_vendor_flat_rate}= 'Y' and {demand.bpart_gcl_id}= 'Labor'
then {orders.vendor_flat_rate}
else
{demand.total_cost}  
 
I need to highlight the fields if they don't match.


Posted By: lockwelle
Date Posted: 15 Jan 2013 at 9:33am
if you right click on your group footer, you will see an option about adding another section. It will add a section, with a letter below your current section. Click on it and drag it above the section.
 
Now you have a 'row' to get the value of the formula so that in the next 'row' your true group footer you can compare the values.
 
 
 
as I think about it, you can probably just augment your formula for use in the color selection...
 
local numbervar x;
if isNull ({orders.is_vendor_flat_rate}) then x:={demand.total_cost}
else if {orders.is_vendor_flat_rate}= 'Y' and {demand.bpart_gcl_id}= 'Labor'
then x:={orders.vendor_flat_rate}
else
x:={demand.total_cost}  
 
if x <> {table.otherField} then
  crRed
Else
  crWhite
 
you would use the same formula in both color decisions, I don't think it is as clean as the other solution, but it is more straight-forward that does not require another group footer.
 
hope one of these works for you.


Posted By: db3712
Date Posted: 15 Jan 2013 at 10:01am
One last question and I'll leave you be.  Thank you very much for your help this afternoon.  Where you say "if x <> {table.otherField} then" color portion of the formula, where do I put that?  I was able to use your first section of the fomula without error.  I just don't know where to apply the color setting portion of the formula.  I'm obviously a newby at this.  Thanks again for everything!


Posted By: lockwelle
Date Posted: 15 Jan 2013 at 10:58am
if you right click on the object that you want to change the background of, you can click on the 'format field', then the 'border' tab. Check the 'background' box, and finally the x-2 to the far right of the 'background' checkbox.
 
you can either copy the code from the formula into each object or call the formula...i've seen it done in other code, but don't do it myself, so you might need research how to do that...i think you just use @formulaName, but I could be wrong.



Print Page | Close Window