Description
IIF returns one of two parts, depending on the evaluation of the expression.
Arguments
expression is a Boolean expression.
truePart is the value returned if expression is True. It can be any simple type (Number, Currency, String, Boolean, Date, Time or DateTime) or range type (Number Range, Currency Range, String Range, Date Range, Time Range or DateTime Range), but it may not be an array.
falsePart is the value returned if expression is False. It must be of the same type as truePart.
Returns
truePart if expression is True and falsePart if expression is False. The type of the returned value is the same as the type of truePart and falsePart.
Action
IIF returns one of two parts, depending on the evaluation of the expression.
Typical uses
IIF can be used as an alternative to the If/Then/Else control structure in some situations.
One situation where IIF may be better than a control structure is when writing record selection formulas so that they can be pushed down to the database server. See
Switch (expr1, value1, expr2, value2, …) for an example. See "Using enhanced record selection formulas" in the Designing Optimized Web Reports chapter of the Crystal Reports User's Guide for an explanation of the techniques involved.
Examples
IIF ({Orders.Order Amount} > 10000, "large order", "standard order")
Returns the String value "large order" if {Orders.Order Amount} is more than $10,000 and the String value "standard order" otherwise.
You can insert a formula field that represents the order amount if the payment has been made already, and is 0 otherwise:
IIF ({Orders.Payment Received}, {Orders.Order Amount}, 0)
Comments
Every argument of the IIF function is evaluated before the result is returned. Thus, you should watch out for undesirable side effects when using IIF. For example, if falsePart results in division by zero, an error will occur, even if expression is True and so truePart is returned.