jrl's avatar
jrl
New Member
5 months ago
Status:
New

PBI DAX INLINE() wrapper

In iterator measures such as SUMX, AVERAGEX, or MINX, it is often more performant to inline calculation logic rather than reference external measures, as referenced measures may be evaluated repeatedly per row. At the same time, manually inlining expressions quickly hurts readability and maintainability.

Many novice DAX users assume that this is where VAR enters the picture. However, VAR evaluates its expression eagerly and caches the resulting value. This behavior is fundamentally different from inlining expression logic, and the distinction is frequently misunderstood—especially when working with iterators or conditional logic such as SWITCH.

In some scenarios, cached variables are both desirable and intentional—for example, when an expensive aggregation is known to be required by the calculation and reused across multiple expressions. In other cases, however, eager caching introduces unnecessary evaluation overhead or prevents expressions from being evaluated only in the branches where they are actually needed.

The proposed INLINE() construct addresses this distinction by introducing an explicit inline‑expansion step that is separate from evaluation and caching. INLINE() is not limited to variables; it can wrap any expression. Conceptually, INLINE() instructs the engine to first resolve referenced measures, variables, and definitions, and then expand them into explicit DAX syntax. When the measure is saved, the model stores and executes the fully expanded DAX expression.

By using INLINE(), developers can treat expressions as pure aliases—focusing on structure, clarity, and reuse—without introducing eager evaluation or duplicated logic. Cached variables can still be used intentionally where appropriate, but INLINE() provides a clear and explicit way to opt into expression‑level inlining when performance characteristics or control‑flow semantics require it. This removes unnecessary trade‑offs between performance, readability, and maintainability, while making developer intent explicit in the code.

Measure examples

No CommentsBe the first to comment

Recent ideas