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
| Function | Description | Example |
|---|---|---|
IF() | Returns one value if a condition is TRUE, another if FALSE | IF(Sales[Amount] > 1000, "High", "Low") |
SWITCH() | Evaluates an expression against multiple possible values or conditions | See example below |
IFERROR() | Returns a value if an expression results in an error | IFERROR([Profit]/[Revenue], 0) |
COALESCE() | Returns the first non-blank value from a list of expressions | COALESCE(Sales[Discount], 0) |
SELECTEDVALUE() | Returns the selected value if only one value is selected, otherwise returns alternate | SELECTEDVALUE(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
| Situation | Function |
|---|---|
| Fallback when data is blank | COALESCE() |
| Handling errors like divide by zero | IFERROR() |
| Assigning grades or bands | SWITCH() |
| Conditional labels or flags | IF() |
| Adapting visuals to user selection | SELECTEDVALUE() |
No questions available.