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>])
ArgumentRequiredDescription
logical_testRequiredAny expression that is TRUE or FALSE.
value_if_trueRequiredThe result when the test is TRUE.
value_if_falseOptionalThe 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")
CountryMargin Status
CanadaBelow target
FranceOn target
GermanyOn target
MexicoBelow target
United States of AmericaBelow target
TotalBelow 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