Tests a Boolean argument and returns one of two results based on whether it is true or false.
For example, you can use the IF THEN ELSE function to ensure that calculations only apply to values that meet certain criteria.
Syntax
IF Boolean argument THEN Result 1 ELSE Result 2
Arguments
Argument | Data type | Description |
Boolean argument | Boolean | The Boolean argument that determines whether the function returns Result 1 or Result 2. If TRUE, the function returns Result 1. If FALSE, the function returns Result 2. |
Result 1 | Number, Boolean, date, time period, list, text | The value to return if the Boolean argument resolves to TRUE. Must be the same data type as Result 2. |
Result 2 | Number, Boolean, date, time period, list, text | The value to return if the Boolean argument resolves to FALSE. Must be the same data type as Result 1. |
The IF THEN ELSE function returns a result of the same data type as the Result 1 and Result 2 arguments.
Syntax example
IF Time Settings.'Current Version' THEN Revenue ELSE 0
Additional information
Alternative syntax
You can also use the syntax used for some other spreadsheet applications. For example:
IF(a > b, x, y)
This formula is equivalent to the formula below:
IF a > b THEN x ELSE y
Indentation in the formula editor
If you use the IF THEN ELSE function in the new modeling experience, each argument of the function is indented within the expanded formula editor.
Boolean results
If you need to return a Boolean result based on certain criteria, it's not always necessary to use the IF THEN ELSE function. Instead you can use operators to create a statement and Anaplan returns a value of TRUE or FALSE based on the cell value. For example, you could use:
a > b
This formula is equivalent to the formula below:
IF a > b THEN TRUE ELSE FALSE
Multiple instances of IF THEN ELSE
You can use IF THEN ELSE multiple times in a formula. However, try to avoid this where possible as such formulas can be difficult to maintain. If your formula requires 10 or more instances of IF THEN ELSE, consider using the LOOKUP function.
Constraints
Match the data type of Result arguments
Both the Result 1 and Result 2 arguments must have the same data type. The target line item must also have the same data type.
Excel equivalent
Examples
General examples of all data types
This example uses two modules. The first module, Values module, contains several line items that contain two values of each data type:
Number 1 | 100 |
Number 2 | 200 |
Boolean 1 | |
Boolean 2 | |
Date 1 | 1/1/2021 |
Date 2 | 2/2/2021 |
Time period 1 | Jan 21 |
Time period 2 | Feb 21 |
List 1 | London |
List 2 | Paris |
Text 1 | Good |
Text 2 | Bad |
The Result 1 and Result 2 arguments use the values above in the formulas in the second module below. The second module also contains a line item used for the Boolean argument of the IF THEN ELSE function.
Scenario 1 | Scenario 2 | |
Boolean argument | ||
Number example
| 100 | 200 |
Boolean example
| ||
Date example
| 1/1/2021 | 2/2/2021 |
Time period example
| Jan 21 | Feb 21 |
List example
| London | Paris |
Text example
| Good | Bad |
Examples using operators
You can use operators such as AND, NOT, or OR in the Boolean argument to create more detailed conditions for the IF THEN ELSE function.
Region A | Region B | Region C | |
Value 1 | 1 | 10 | 10 |
Value 2 | 10 | 1 | 10 |
IF 'Value 1' >= 10 AND 'Value 2' >= 10 THEN "A" ELSE "B" | B | B | A |
IF 'Value 1' >= 10 OR 'Value 2' >= 10 THEN "A" ELSE "B" | A | A | A |