IF
defines a condition and returns a result when that condition is met, or returns a different result if that condition is not met.
Note: IF
is similar to
but acts only on a single condition, and can return only one true result or one false result.CASE
Sample usage
Calculate a bonus rate if actual sales exceed forecast sales:
Syntax
Parameters
condition
- The expression to evaluate.condition
can be any valid Boolean expression.true_result
- the value to return ifcondition
is true.true_result
can be any valid expression.false_result
- the value to return ifcondition
is false.false_result
can be any valid expression.
Examples
Return a dimension based on a parameter selection.
For example, you can create a Boolean parameter, Forecast Parameter, and use it to return a column of forecasted data. Otherwise, use the actual data:
Identify records that are older than a certain number of days before today:
A more complex condition with logical AND, and regular expression matching:
IF
is limited to returning only one of two possible results: the true_result or the false_result. To create a function that can return more possible results, use CASE or simple CASE instead.