Wednesday, February 16, 2011

Conditional Formatting in Crystal Reports

What exactly is Conditional Formatting in Crystal Reports?

Conditional formatting, put simply, is formatting (e.g, font color, font style, etc.) applied to data that meets certain rules or conditions. For example, the person requesting the report would like the Total Sales field to have a green background if the amount is greater than $5000.

But how is this conditional formatting magic done?

  1. Select the field to be formatted.
  2. Right-click and choose the border tab – background color is in the center of that tab.
  3. Do not click in the color checkbox, rather click on the X+2 box directly to the right of the background color. The Formula Editor will open.
  4. In the Operators column choose Control Structures for the If Then Else.
  5. Double-click to bring that down to the work area. At the top of the functions column, you’ll see two new categories associated with formatting text/numbers:
    1. Formatting Functions
    2. Color Constants
  6. Now the tricky part: you have to construct a formula. I’ve included a couple of examples below.
if Sum ({Orders.Order Amount}, {@GroupSort})>5000
then crGreen else crNoColor

Note that the colors are preceded by cr in lower case – Crystal Reports needs this, so do not enter a color name without it. Also note that the else argument is followed by crNoColor. The else could also be followed by DefaultAttribute, like so:

if Sum ({Orders.Order Amount}, {@GroupSort})>5000
then crGreen else DefaultAttribute

The results would be the same but the second formula would revert back to whatever the formatting color was that did not meet the condition. Of course, the formulas could be much more complex but the logic remains the same. If the formula returns true do this othewise do something else.

Happy formatting!

2 comments:

Anonymous said...

My spouse and i knowledgeable numerous details using this web page, I had to help recharge
the internet site many times just before getting it
for you to download properly. I was pondering if the internet hosting is okay?
Not really that We're complaining, however slow packing scenarios situations may often have an affect on your current positioning on the internet and will deterioration a person's
good quality credit score in case promoting by using bing.
Anyways I’m introducing this kind of Rss or atom to help my
personal e-mail and may seek out much more of the individual enjoyable written content.
Also visit my web blog ... background Investigation

Anonymous said...

I like the helpful info you supply on your articles.
I will bookmark your weblog and test once more right here
regularly. I'm relatively certain I'll be informed many new
stuff proper here! Best of luck for the following!

my weblog; battlefield 4 campaign cheats pc