IF function is a Power BI logical function in DAX that checks whether a condition is satisfied, and returns one value in case of TRUE else another value in case of FALSE.
It returns a single value of any type.
If the value referenced in the expression is a column, IF returns the value that corresponds to the current row.
DAX SYNTAX
IF(<logical_test>,<value_if_true>[, <value_if_false>])
<logical_test> is any value or an expression that can be evaluated to TRUE or FALSE.
<value_if_true> is a value that is returned if the <logical_test> is TRUE.
<value_if_false> is a value that is returned if <logical_test> is FALSE. It is an optional.
Lets take an example, here we have a sample table which consists a supplier data as shown below.
Suppose, you want to display the status that is Level1 and Level 2 based total quantity by category.
If total quantity is >500 then display “Level 1” else “Level 2”. So first you need to get total quantity for each individual supplier by category.
Lets create a measure TotalQtySum which calculates the sum of quantity.
As you can see, TotalQtySum calculates the sum of quantity.
Now, to display the status we will check the total quantity, if total quantity is >500 then display “Level 1” else “Level 2”.
Lets create a following measure which uses IF function to check the condition.
Status = IF( [TotalQtySum] >500 ,"Level 1" ,"Level 2" )
Lets drag the measure into table visual to see the output.
As you can see, it returns the status value Level 1 where TotalQtySum is greater than 500 else Level 2.
1,943 total views, 2 views today