Power BI Row Context and Filter Context
Every DAX formula runs inside a context. Context decides which rows the formula can see. Two kinds exist: row context and filter context. Understanding both turns DAX from guesswork into logic.
Row Context
Row context means the formula works on one row at a time. Calculated columns create row context automatically. Picture a cashier at a till who scans each item individually. The cashier handles the current item and ignores every other item in the basket.
Line Total = Sales[Quantity] * Sales[Price]
Row 1: Quantity 2 x Price 50 = 100
Row 2: Quantity 5 x Price 20 = 100
Row 3: Quantity 1 x Price 300 = 300
(each row calculates alone)
The formula reads Quantity and Price from the current row. No total across rows appears. Row context offers no view beyond the current row.
Filter Context
Filter context means the formula sees a filtered set of rows. Measures run inside filter context. Slicers, visual axes, page filters, and report filters all build it. Picture a store manager who opens the sales book and looks only at the Electronics section for January. The manager sees just the rows that pass those filters.
Total Revenue = SUM(Sales[Revenue])
All Sales Rows (1000)
|
[Slicer: Year = 2026] --> 400 rows
|
[Axis: Category = Phones] --> 90 rows
|
SUM(Revenue) runs on these 90 rows
The same formula returns a different answer in every cell of a visual, since every cell carries a different filter context.
How a Matrix Builds Filter Context
| 2025 | 2026 | |
|---|---|---|
| Phones | Category=Phones, Year=2025 | Category=Phones, Year=2026 |
| Laptops | Category=Laptops, Year=2025 | Category=Laptops, Year=2026 |
Each cell receives filters from its row header and its column header. The measure calculates once per cell with those filters applied.
Side-by-Side View
| Feature | Row Context | Filter Context |
|---|---|---|
| Created by | Calculated columns and iterators | Slicers, axes, filters, CALCULATE |
| Sees | One row | A set of filtered rows |
| Typical use | Row-by-row math | Totals and KPIs |
A Classic Trap
A calculated column that uses SUM returns the grand total on every row. Row context does not filter the table, so SUM sees all rows. The same trap fools many beginners:
Wrong Share = SUM(Sales[Revenue])Every row shows the same number. A measure fixes the problem, since a visual supplies the filter context.
Context Transition
Wrapping a formula in CALCULATE converts the current row into filters. Power BI calls this context transition. The row stops being a lone row and becomes a filter on the table. A calculated column such as this one counts orders for each customer:
Orders Per Customer = CALCULATE(COUNTROWS(Orders))Inside a Customers table, the current customer row turns into a filter on related orders. COUNTROWS counts only that customer's orders.
Worked Example: A School Marks Sheet
A Marks table holds Student, Subject, and Score. A calculated column Pass Flag checks each score against 40 and runs in row context. A measure Average Score calculates the mean for whichever subject or class a user selects in a slicer, which is filter context. The column labels individual rows, and the measure summarizes groups.
Key Points
- Row context handles one row at a time and appears in calculated columns.
- Filter context handles a filtered group of rows and appears in measures.
- Visuals, slicers, and filters build filter context automatically.
- CALCULATE turns row context into filter context.
- Check which context a formula runs in whenever a result looks wrong.
