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.
<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 go through an example to see IF Function in action.
Here we have a sample table which consist a supplier data as shown in table visual.
Suppose, you want to display the status based on the category wise total quantity sum, if total quantity sum is >500 then display “Level 1” else “Level 2”.
So first you need to get category wise total quantity sum for individual supplier.
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 based on the check on total quantity sum, if total quantity sum is >500 then display “Level 1” else “Level 2” ,we creates 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 status .
As you can see, it returns status value Level 1 where TotalQtySum is greater than 500 else Level 2