Daily DAX : Day 442 IF.EAGER
Power BI DAX Function: IF.EAGER
Overview
The IF.EAGER function in DAX is a logical function that evaluates a condition and returns one value if the condition is TRUE, and another (optional) value if FALSE. It behaves functionally like the standard IF function but differs in how the DAX engine evaluates its arguments.
Syntax
IF.EAGER(, [, ])
- logical_test: Any expression that evaluates to TRUE or FALSE.
- value_if_true: The value returned if the condition is TRUE.
- value_if_false: (Optional) The value returned if the condition is FALSE. If omitted, BLANK() is returned.
Key Difference from IF
The standard IF function uses either strict or eager evaluation depending on what the DAX engine determines is optimal. In contrast, IF.EAGER always uses eager evaluation:
- Both
value_if_trueandvalue_if_falseexpressions are evaluated before checking the condition. - Then, based on the condition, one of the pre-computed results is selected.
This is equivalent to using variables in a standard IF:
VAR _true = VAR _false =
RETURN
IF(, _true, _false) Use Cases
Use IF.EAGER in performance optimization scenarios, especially when:
- Both branches are computationally similar in cost, and eager evaluation avoids multiple scans of large tables (common in iterations).
- You need to force eager evaluation for better query plans in complex measures (e.g., inside iterators like SUMX or AVERAGEX over large datasets).
- Testing shows a clear performance improvement over standard
IF.
Note: Do not use it blindly—test performance, as eager evaluation can be slower if one branch is much more expensive than the other.
Simple Example
Category = IF.EAGER(
[Sales] > 1000,
"High Sales",
"Low Sales"
)
This returns "High Sales" if Sales > 1000, else "Low Sales". Both string literals are "evaluated" upfront (trivial here), but in complex cases, both branches compute fully.
Comments
Post a Comment