Webucator blogs about online learning and training.

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.

6 Responses to “Conditional Formatting in Crystal Reports”

  1. Nice post.

    I have to insert a conditional formatting formula in my report on some fields. Do you know how to use the “Rounding” formula?

    I have this problem with regional settings and differences in decimals and rounding for some specific fields. If i change the property for a field it also changes the type Custom and therefore no possibility to switch between “.” and “,” as a decimal separator.

    Your help would be invaluable.

    - Arne Kristian

  2. Hi Arne,

    The Rounding formula can be tricky. I’m teaching an Xcelsius class the next couple of days, but I’ll try to get some time to do a post on it very soon.

    MaryPat

  3. Nice Stuff. Can you please also tell us how can we use javascript in formula editor to do the conditional formatting ?

  4. Ravi, I am not positive, but I do not “think” that’s possible. In my experience, formulas have only been be written in Visual Basic or Crystal Reports script. If you find out differently, please let me know.

  5. Arne, I am working on your ’rounding issues’ and will have the blog up this week. Great subject!!

  6. [...] general, Crystal Reports users set up the default formatting to display the data in the way it is to be used most often. However, when it is necessary to be [...]

Tweetbacks

© Webucator, Inc. All rights reserved. | Toll Free: 877-932-8228 | Outside the USA: 315-849-2724 | Fax: 315-849-2723