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!

We cover conditional formatting in our Introduction to Crystal Reports class.

Hear about our latest Crystal Report blogs, classes, and webinars by signing up for our newsletter.

About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.


6 thoughts on “Conditional Formatting in Crystal Reports”