DAX Conditional Funtions

Perform logic-based calculations in DAX

Conditional functions in DAX allow you to perform logic-based calculations. They return different results depending on whether certain conditions are met—similar to IF statements in Excel or programming languages.

Common Conditional Functions in DAX

FunctionDescriptionExample
IF()Returns one value if a condition is TRUE, another if FALSEIF(Sales[Amount] > 1000, "High", "Low")
SWITCH()Evaluates an expression against multiple possible values or conditionsSee example below
IFERROR()Returns a value if an expression results in an errorIFERROR([Profit]/[Revenue], 0)
COALESCE()Returns the first non-blank value from a list of expressionsCOALESCE(Sales[Discount], 0)
SELECTEDVALUE()Returns the selected value if only one value is selected, otherwise returns alternateSELECTEDVALUE(Customer[Region], "Multiple")

Detailed Examples

IF Function

Rating = IF(Sales[Amount] > 1000, "High", "Low")

Returns "High" if the amount is over 1000, otherwise "Low".

SWITCH Function

Grade = 
SWITCH(
    TRUE(),
    Marks[Score] >= 90, "A",
    Marks[Score] >= 80, "B",
    Marks[Score] >= 70, "C",
    "F"
)

This works like a multi-condition IF block.

IFERROR Function

Safe Division = IFERROR(Sales[Profit] / Sales[Revenue], 0)

Returns 0 if division by zero or any error occurs.

COALESCE Function

Final Price = COALESCE(Product[Price], 0)

If Price is blank, it returns 0.

SELECTEDVALUE Function

SelectedRegion = SELECTEDVALUE(Customer[Region], "Multiple Selected")
  • If one region is selected, it returns it.
  • If none or multiple, returns "Multiple Selected".

Use Cases

SituationFunction
Fallback when data is blankCOALESCE()
Handling errors like divide by zeroIFERROR()
Assigning grades or bandsSWITCH()
Conditional labels or flagsIF()
Adapting visuals to user selectionSELECTEDVALUE()
No questions available.