DAX Logical Functions
Logical Functions in DAX
Logical functions in DAX are used to perform operations based on conditions returning different results depending on whether those conditions are TRUE or FALSE.
They’re essential for conditional calculations, custom categories, and dynamic KPIs.
Common Logical 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() | Tests multiple conditions and returns the first match | See below |
AND() | Returns TRUE if both conditions are TRUE | AND(Sales[Amount]>500, Sales[Region]="West") |
OR() | Returns TRUE if any condition is TRUE | OR(Sales[Amount]>500, Sales[Region]="East") |
NOT() | Reverses a logical value | NOT(Sales[IsActive]) |
IFERROR() | Returns a custom value if the expression results in an error | IFERROR([Measure], 0) |
TRUE() / FALSE() | Explicitly returns the boolean TRUE or FALSE | IF(Sales[Returned] = TRUE(), "Returned", "Not Returned") |
SWITCH()
Function
Category =
SWITCH(
TRUE(),
Sales[Amount] > 1000, "High",
Sales[Amount] > 500, "Medium",
"Low"
)
This works like a multi-condition IF, checking conditions in order and returning the first match.
Key Notes
- Logical functions are booleans: They return
TRUE
orFALSE
. - Often used in calculated columns, measures, or filters.
- Logical conditions can be combined using
AND
,OR
,NOT
.
Real-World Use Cases
Use Case | Example |
---|---|
Tag high-value orders | IF(Sales[Amount] > 1000, "High", "Low") |
Prevent errors in division | IFERROR([Profit]/[Sales], 0) |
Create category bands | Use SWITCH() or nested IF() s |
No questions available.