Stop 08 · Filter Context & CALCULATETopics · 8/9

Context Transition

Part of the Power BI Roadmap

In short

Why does CALCULATE ( SUM ( Sales[Amount] ) ) in a calculated column give each customer's own total, while SUM alone gives the grand total? The answer is context transition, the trickiest and most interviewed idea in DAX.

When CALCULATE runs inside a row context, such as an iterator or calculated column, it turns the current row into an equivalent filter context. Every measure reference does this automatically.

The jaadu at a reception desk holds up a visitor's ID card and slots it into a big filing cabinet, which slides open to just that person's folder.

Think of it like this

Turning a face into a search filter

A receptionist sees a visitor standing in front of her (row context) but can't pull up records by face. She reads the ID card, types the name into the search box (filter context), and the system shows only that person's records. CALCULATE does that: it turns the current row into a filter.

Watch it happen

Lifetime Sales column on the Customer row for Asha

Row: Asha
CALCULATE
Filter: Asha
Sales rows
₹72,000

1/5In a calculated column on Customer, there's a row context for Asha, but no filter.

The big ideas

What you need to know

Row becomes filter

CALCULATE inside a row context turns the current row's values into an equivalent filter context.

Measures do it silently

Referencing [Total Sales] wraps it in an invisible CALCULATE, so context transition happens automatically.

Common inside iterators

AVERAGEX ( VALUES ( Customer[CustomerKey] ), [Total Sales] ) works because each customer row becomes a filter.

Duplicates and speed

If two rows are identical, the filter matches both, so values can double. And transitioning millions of rows is slow.

See it in code

Walk through the code

dax
1-- Calculated columns on the Customer table2Wrong Lifetime Sales = SUM ( Sales[Amount] )3 4Lifetime Sales = CALCULATE ( SUM ( Sales[Amount] ) )5 6Lifetime Sales (Measure Ref) = [Total Sales]7 8-- A measure that relies on context transition9Avg Sales per Customer =10AVERAGEX ( VALUES ( Customer[CustomerKey] ), [Total Sales] )

1/4No CALCULATE, so no transition. Every customer shows the grand total of all sales.

Three columns on Customer and one measure. Only the first ignores the current customer.

Save yourself the pain

Common mistakes

Oops

Calling a measure inside SUMX over a big fact table, like SUMX ( Sales, [Total Sales] ).

Do this instead

Each of millions of rows triggers a transition, and duplicate rows get double counted. Iterate a dimension or use columns directly.

Oops

Expecting a variable holding a measure to transition inside a later iterator.

Do this instead

Variables are evaluated once where defined. Reference the measure inside the iterator instead.

Your mission

See the transition

~20 min

Quick check

In a calculated column on Customer, why does [Total Sales] give each customer's own sales?

Go deeper

  1. 1Create a calculated column with and without CALCULATE and compare results.
  2. 2Explain why referencing a measure inside SUMX behaves differently from the raw expression.
  3. 3Watch a SQLBI video on context transition, then re-explain it in your own words.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge