DAX IF function
Returns one value when a condition is true, and another when it is false.
IF turns numbers into decisions: on target or not, big or small. In a measure, the condition is usually about another measure.
Syntax
IF(<logical_test>, <value_if_true>[, <value_if_false>])| Argument | Required | Description |
|---|---|---|
| logical_test | Required | Any expression that is TRUE or FALSE. |
| value_if_true | Required | The result when the test is TRUE. |
| value_if_false | Optional | The result when the test is FALSE. Blank if left out. |
Returns: Either value. If they have different types, DAX converts them to one type.
Examples
Calculated on the free practice data (table financials), with [Total Sales] = SUM(financials[Sales]) and [Total Profit] = SUM(financials[Profit]).
1. Margin status by country
Margin Status = IF(DIVIDE([Total Profit], [Total Sales]) >= 0.15, "On target", "Below target")| Country | Margin Status |
|---|---|
| Canada | Below target |
| France | On target |
| Germany | On target |
| Mexico | Below target |
| United States of America | Below target |
| Total | Below target |
France and Germany reach a 15% margin; the other three countries don't.
Good to know
- Combine conditions with && (and) and || (or): IF([Sales] > 0 && [Profit] < 0, …).
- With three or more outcomes, SWITCH(TRUE(), …) is easier to read than nested IFs.
Related functions
Official reference: IF function on Microsoft Learn