Context transition in DAX

Context Transition is the process of turning row context into filter context.
• By default, calculated columns understand row context but not filter context.
• To create filter context at the row-level in calculated columns, we can use CALCULATE.

Go to the Data tab in the Power BI Desktop, click on New column, to create a calculated column.

DAX

Column 2 = SUM(Sheet1[10th Marks])

We can see in the image below that the expression isn't evaluated in a filter context.

Context transition in DAX

To force the evaluation of the SUM(Sheet1[10th Marks]) expression for each student, a context transition must take place that applies the row context column values to filter context. We can accomplish this transition by using the CALCULATE function without passing in filter expressions.

Note: The CALCULATE function used without filters achieves a specific requirement. It transitions row context to filter context. It's required when an expression (not a model measure) that summarizes model data needs to be evaluated in row context. This scenario can happen in a calculated column formula or when an expression in an iterator function is evaluated. Note that when a model measure is used in row context, context transition is automatic.

Modify the calculated column definition so that it produces the correct result.

DAX

Column 2 = CALCULATE (SUM(Sheet1[10th Marks]))
Context transition in DAX

In this case, the CALCULATE function applies row context values as filters, known as context transition.

If we reference measures in an expression that's evaluated in row context, context transition is automatic. Thus, we need to pass measure references to the CALCULATE function.

Modify the calculated column definition, which references the [10th Marks Measure] measure, and notice that it continues to produce the correct result.

DAX

Column 2 = [10th Marks Measure]
Context transition in DAX