Understanding Row Context vs Filter Context in DAX

What is Row Context?

If you’ve worked with DAX in Power BI or Excel, you’ve probably encountered situations where your formulas don’t return what you expected. More often than not, the culprit is a misunderstanding of context—specifically, the difference between row context and filter context.

These two types of context are fundamental to how DAX evaluates formulas, and understanding them is essential for writing effective measures and calculated columns. Let me break down what each one means and how they work.

Row context is exactly what it sounds like: DAX is evaluating your formula one row at a time. When row context exists, DAX can “see” the values in each column for the current row.

Where you’ll find row context:

  • Calculated columns
  • Iterator functions like SUMX, FILTER, AVERAGEX
  • Inside row-by-row operations

For example, if you create a calculated column in a Sales table:

Total Price = Sales[Quantity] * Sales[Unit Price]

DAX evaluates this formula for each row in the table. For row 1, it multiplies the Quantity in row 1 by the Unit Price in row 1. For row 2, it uses row 2’s values, and so on. That’s row context in action.

The key limitation: Row context doesn’t automatically filter related tables. If you reference a column from a related table within row context, you need to explicitly use functions like RELATED or RELATEDTABLE to navigate the relationships.

What is Filter Context?

Filter context is the set of filters currently applied to your data model. It determines which rows are “visible” to your calculation at any given moment.

Where filter context comes from:

  • Slicers and filters on your report
  • Row and column headers in a matrix or table visual
  • Filter pane selections
  • The CALCULATE function (which modifies filter context)

When you create a measure like:

Total Sales = SUM(Sales[Amount])

The value you see depends entirely on the filter context. If you’ve filtered to a specific year, region, or product, the measure will only sum the Amount for rows that match those filters.

The key point: Filter context affects all calculations in your measures, cascading through table relationships according to the relationships you’ve defined in your model.

The Critical Difference

Here’s where things get interesting—and where many people get confused:

Row context does NOT create filter context.

This is crucial. When you’re iterating through rows with an iterator function like SUMX, you have row context for each iteration, but you haven’t created any filters on your model. If you want to use a measure inside an iterator, you need to convert the row context into filter context.

That’s where the CALCULATE function becomes your best friend. CALCULATE can transform row context into filter context, allowing measures to evaluate correctly within iterations.

A Practical Example

Let’s say you want to calculate the percentage of total sales for each product. You might try:

Product Sales % = 
DIVIDE(
    SUM(Sales[Amount]),
    SUMX(ALL(Sales), Sales[Amount])
)

But this won’t work as expected in an iterator context. Instead, you’d need:

Product Sales % = 
DIVIDE(
    [Total Sales],
    CALCULATE([Total Sales], ALL(Sales))
)

Here, CALCULATE creates the filter context needed for the measure to evaluate correctly.

Quick Reference

Row Context:

  • Iterates row by row
  • Created by calculated columns and iterator functions
  • Can directly reference column values in the current row
  • Doesn’t automatically propagate through relationships
  • Doesn’t filter the model

Filter Context:

  • Filters which rows are visible
  • Created by visuals, slicers, and CALCULATE
  • Affects all measures
  • Propagates through relationships
  • Determines what data your measures see

The Bottom Line

Mastering the distinction between row context and filter context is one of those “aha” moments in your DAX journey. Once it clicks, you’ll understand why your formulas behave the way they do, and you’ll be able to write more sophisticated calculations with confidence.

The simple rule of thumb: calculated columns work row by row (row context), while measures work with filtered data (filter context). And when you need to bridge the two, CALCULATE is your tool of choice.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *