Sub topic 1
How DAX Decides What a Formula Sees
Prerequisites
Assume you know tables, columns, one-to-many relationships, simple aggregations such as SUM, and the difference between measures and calculated columns. You should also be able to build a basic Power BI visual.
Evaluation context
DAX evaluates every expression inside an evaluation context. The context determines which rows an expression can see. Two contexts matter most:
- Filter context restricts tables to rows selected by slicers, visuals, or formula filters.
- Row context points to one current row while DAX evaluates an expression.
A measure usually starts with filter context. A calculated column starts with row context. Iterator functions, such as SUMX, create row context while they process a table.
Sales Amount =
SUMX ( Sales, Sales[Quantity] * Sales[Unit Price] )Here, the existing filter context chooses the Sales rows. SUMX then evaluates the multiplication once for each selected row.
Filter context: slicers, visuals, and filter arguments
Suppose a report visual groups sales by Product[Category]. Each category creates a different filter context. A slicer for year adds another filter. The measure sees only rows allowed by all active filters.
CALCULATE changes that context by applying filter arguments:
Red Sales =
CALCULATE (
[Sales Amount],
Product[Color] = "Red"
)This evaluates [Sales Amount] with a filter for red products. By default, a filter on the same column can replace an existing filter on that column.
Row context: working on one row at a time
A calculated column has a row context for its current row. It can read columns directly:
Line Amount = Sales[Quantity] * Sales[Unit Price]SUMX ( Sales, ... ) also creates a row context, but only during that iteration. Row context by itself does not filter another table. This distinction becomes important when relationships are involved.
How filters travel across relationships
In a star schema, a relationship connects a dimension table, such as Product, to a fact table, such as Sales. A filter on the one-side dimension normally propagates to matching rows on the many-side fact table.
Exercise
Which context does a slicer create, and which context does SUMX create while iterating?
Show answer
A slicer creates filter context. SUMX creates row context for each row it processes.