Home | SkillForge Blog | Using Conditional Formatting for Sections in Crystal Reports

Using Conditional Formatting for Sections in Crystal Reports

Business Objects, Crystal Reports

When we use conditional formatting, we usually think of it in terms of things like making better sales numbers green and lower numbers red. But we can be more subtle than that in Crystal.

No conditional formatting
A common example is where records are incomplete, or where data are filled in at some levels and not others. Sales databases might have country-level data, and city-level data, but not state-level if there are no states in a small-enough country. So if there are no states, or provinces, we don’t want to see blank spaces in the report.

Section expert
We can go into the Section Expert in such a report, and having set up grouping for the levels in question (country, state/province, city), we select the state/province group header. Then we go to the Common tab on the right, and click, not the Suppress (No Drill-Down), as we don’t want this to be the norm, but the X-2 button next to it. (We want to have the suppression be as needed—that is, conditional.)

Conditional formula
The formula we write to look at it asks, basically, if there’s anything to show. More specifically, in our example, are there fewer than two states or provinces? (This is the “conditional” part.) If so, we don’t need to see the (blank) space where the information would appear. And we can use the same formula in the section footer, too.

Conditional formatting done
This is a very useful point, which has application on a wider scale within the section organization. We can suppress sections, but make exceptions, so as to show something when it’s important; we can also have a section show, but not when there’s nothing to show or the info is unnecessary or redundant.

The hard part is writing the formula, but if one can phrase the condition clearly, writing it is easier. Sketching the overall structure can sometimes help too. (May sound kind of old-fashioned, but it’s tried-and-true.)

To learn more, take a look at our Crystal Reports training.