The If-Then-Else Statement

If-then-else formulas (sometimes called “if statements”) allow you to set con­ditions within formulas. In the Formula Editor, you can find the if-then-else statement under Operators, Control Structures, but I usually find it easier to simply type the words myself.

The basic rationale behind if-then-else statements is that if the condition is met then does this, and if the condition is not met then do that or do nothing. A single formula can have several conditions and instructions. An easy ex­ample that works with the sample report in this chapter is “if the total order amount is over a certain value, then award a discount.” I did not include an else clause because if the condition is not met, I want nothing to happen.

Also, as mentioned earlier, another common use for conditional formulas is to format fields on a report, such as font color, currency symbol, or many other formatting options found in the Format Editor. A basic if-then-else formula applied to the font color format attribute might read:

With this conditional formula, the number field prints in red font color if the actual value of the field is less than or equal to zero. If the condition is not met, then the field prints in black font color. In this example, the else clause is actually not necessary. Without it, SCR would apply the Windows default font color, black, when the condition was not met.

Facebook
Twitter
Pinterest