Formatting Data Conditionally

Objectives

After completing this lesson, you will be able to:

  • Use formulas to conditionally format data display

Conditional Formatting

Conditional formatting using formulas.

While most conditional formatting can be implemented using the Highlighting Expert, there are certain limitations that can be mitigated using formatting formulas.

Limitations of the Highlighting Expert

The Highlighting Expert is quicker and easier to use than the Formula Workshop (creating your own formula condition).

The Highlighting Expert, however, isn't as flexible as the Formula Workshop. To use the formatting capabilities of Crystal Reports to their full potential, create your own conditional formatting formulas with the Formula Workshop.

On or Off Properties

An on or off property uses a check box. When the check box is turned on, the property is always applied. When the check box is turned off, the property is never applied. The Drop Shadow property for a Border is an example of an on or off property. When you conditionally apply an on or off property, the program applies the attribute when the condition is met and doesn't apply the attribute when the condition isn't met. Therefore, to set an on or off property, you must create a Boolean formula that returns yes for every value to which you want to apply the attribute. Whenever the result of the formula is no, the attribute is set to off.

Attribute Properties

A conditional attribute property tests to see which of two or more conditions are met. The program then applies the formatting appropriate to the condition. For example, assume you want values under quota printed in red and all other values printed in black. The program tests to see whether the value is under quota or not. If it's under quota, then it applies the red attribute; if it isn't, then it applies the black attribute.

Use an If-Then-Else formula for this kind of conditional formatting.

Functions List Attributes

When conditional attribute properties are set up, Crystal Reports loads a selection of attributes into the Functions list in the Formula Workshop. Double-click any of these attributes to add them to a formula. For example, if you're setting horizontal alignment conditionally, the Functions list contains attributes including:

  • DefaultHorAligned

  • LeftAligned

  • Justified

If you're setting borders conditionally, the Functions list contains attributes including:

  • NoLine

  • SingleLine

  • DashedLine

Note
Always include the Else keyword in conditional formulas; otherwise, values that don’t meet the If condition may not retain their original format. To retain the original format of values that don’t meet your IF condition, then use the DefaultAttribute function.

The program tests each record to see which of two or more conditions were met and applies the formatting appropriate to the condition. All attribute property options are listed within the Format Formula Editor for your use.

The ability to conditionally format fields and objects gives you more control over the presentation of your data in the report.

Use Functions and Formulas

Use Functions and Formulas

Log in to track your progress & complete quizzes