IF DAX Function (Logical)
Checks whether a condition is met, and returns one value if TRUE, and another value if FALSE.
Syntax
Parameter | Attributes | Description |
---|---|---|
LogicalTest |
Any value or expression that can be evaluated to TRUE or FALSE. |
|
ResultIfTrue |
The value that is returned if the logical test is TRUE. |
|
ResultIfFalse | Optional |
The value that is returned if the logical test is FALSE. |
Return values
Either ResultIfTrue or ResultIfFalse expression result, depending on LogicalTest.
Remarks
Using IF can generate multiple branches of code execution that could result in slower performance at query time.
Then IF can return BLANK as one of the results, there are cases where using DIVIDE to obtain the same result could produce a faster query plan.
The following code returns BLANK if LogicalTest is false.
IF ( <LogicalTest>, <ResultIfTrue> )
The previous code is semantically equivalent to the following expression:
DIVIDE ( <ResultIfTrue>, <LogicalTest> )
Related articles
Learn more about IF in the following articles:
-
Optimizing IF conditions by using variables
This article describes a very common optimization pattern that relies on variables to optimize conditional expressions in DAX. » Read more
-
Understanding eager vs. strict evaluation in DAX
This article describes the differences between eager evaluation and strict evaluation in DAX, empowering you to choose the best evaluation type for your data models. » Read more
-
Optimizing IF and SWITCH expressions using variables
This article describes how variables should be used in DAX expressions involving IF and SWITCH statements in order to improve performance. » Read more
-
From SQL to DAX: Implementing NULLIF and COALESCE in DAX
This article describes how to implement a syntax equivalent to the T-SQL function NULLIF and the ANSI SQL function COALESCE, in DAX. » Read more
-
Optimizing mutually exclusive calculations
This article describes how to optimize DAX expressions with mutually exclusive calculations that might cause slow query performance. » Read more
-
Optimizing conditions involving blank values in DAX
This article describes how blank values considered in a DAX conditional expression can affect its query plan and how to apply possible optimizations to improve performance in these cases. » Read more
Related functions
Other related functions are:
Last update: Jan 11, 2021 » Contribute » Show contributors
Contributors: Alberto Ferrari, Marco Russo
MSDN documentation: https://docs.microsoft.com/en-us/dax/if-function-dax