Sub topic 2
Filter context: slicers, visuals, and filter arguments
This chapter assumes you know the basics of a data model (tables, columns, one-to-many relationships). It also assumes you can write simple aggregations such as SUM and COUNTROWS, and that you know a measure from a calculated column. You should be able to build a basic report visual. Row context and relationship propagation get their own chapters, so this chapter stays on filter context itself.
What a filter context is
A filter context is the set of filters that are active at the moment DAX evaluates an expression. Each filter restricts one or more columns to a set of allowed values. Aggregation functions only see the rows that survive those filters.
Take this measure:
Sales Amount =
SUMX ( Sales, Sales[Quantity] * Sales[Unit Price] )The formula text never mentions a year, a color, or a customer. It still returns a different number in each cell of a report, because each cell supplies a different filter context. The formula says what to calculate. The filter context says which rows to calculate it over.
A filter context does not point at a row, and it does not loop over anything. It is a restriction on the tables. The measure above is evaluated once per cell, against whatever rows the restriction leaves.
Where filters come from
A single cell can be filtered by several sources at once. All of them end up in the same filter context.
- Row and column headers of a visual. In a matrix, each cell is filtered by the values in its row header and its column header.
- Slicers. Each selection in a slicer filters the slicer's column for every visual it targets.
- The Filters pane. Filters at visual, page, or report level work like slicers that the viewer does not see.
- Cross-filtering and highlighting. Selecting a bar in one visual filters the other visuals on the page.
- Filter arguments of
CALCULATE. Code can add filters, or change the existing ones, for one evaluation. - Row-level security. Role rules apply filters to the tables before any report filter.
The first five sources are described the same way in DAX: a set of allowed values for one or more columns.
A worked example
Assume these Sales Amount values, split by Product[Color] and Date[Year]:
| Color | 2024 | 2025 | All years |
|---|---|---|---|
| Red | 150 | 250 | 400 |
| Blue | 100 | 200 | 300 |
| Black | 150 | 150 | 300 |
| All colors | 400 | 600 | 1000 |
Now put Color on the rows of a matrix and add a slicer on Date[Year] with 2025 selected. The matrix shows:
| Color | Sales Amount |
|---|---|
| Red | 250 |
| Blue | 200 |
| Black | 150 |
| Total | 600 |
The filter context of each cell is:
- Red row:
Color = RedandYear = 2025. - Blue row:
Color = BlueandYear = 2025. - Total row:
Year = 2025only.
The total row is not the sum of the visible rows. DAX evaluates the same measure again, with fewer filters, because the row header contributes no filter there. For Sales Amount the two results agree. For a distinct count or an average they usually do not. The total of a non-additive measure is a separate evaluation, not an addition.
How filters combine
Two rules cover most cases.
- Different columns intersect.
Color = RedandYear = 2025together keep only the rows that satisfy both. - Several values in the same column act as a list. Selecting Red and Blue in a slicer filters
Colorto the set {Red, Blue}. A row passes if its color is in the set.
Filters on the same column from different sources also intersect. If a slicer selects Red and a matrix row is Blue, the result is the intersection of {Red} and {Blue}, which is empty. The cell shows blank. This is the most common reason a "correct" matrix has missing rows or empty cells.
Filters on one column can also narrow filters on a different column, through relationships. A slicer on Product[Category] filters Sales even though Sales has no category column. That propagation is the subject of the next chapters. For now, the point is that the filter context covers every table of the model, not only the table you are aggregating.
Filter arguments in CALCULATE
CALCULATE evaluates an expression in a modified filter context. Its first argument is the expression. The remaining arguments are filters.
Red Sales =
CALCULATE ( [Sales Amount], Product[Color] = "Red" )The boolean expression Product[Color] = "Red" is shorthand. DAX expands it to a table of allowed values, roughly FILTER ( ALL ( Product[Color] ), Product[Color] = "Red" ). That table becomes a filter on Product[Color].
The important behavior is what happens to the filter that was already there. A filter argument on a column replaces any existing filter on that same column. Filters on other columns stay.
Put Red Sales in the matrix with Color on the rows and the 2025 slicer active:
| Color | Sales Amount | Red Sales |
|---|---|---|
| Red | 250 | 250 |
| Blue | 200 | 250 |
| Black | 150 | 250 |
| Total | 600 | 250 |
In the Blue row, the row header filters Color to Blue. CALCULATE replaces that with Color = Red. The Year = 2025 filter is untouched, so every row shows red sales for 2025.
Several filter arguments are combined with AND:
Red Sales 2025 =
CALCULATE (
[Sales Amount],
Product[Color] = "Red",
'Date'[Year] = 2025
)Each argument is evaluated in the filter context as it was before CALCULATE started. After all of them are computed, they are applied together to produce the new filter context. Their order does not matter.
Keeping the existing filter
Sometimes replacing is not what you want. KEEPFILTERS makes the new filter intersect with the existing one on the same column.
Red Sales Within Selection =
CALCULATE (
[Sales Amount],
KEEPFILTERS ( Product[Color] = "Red" )
)In the matrix above, the Red row shows 250. The Blue row is blank, because {Blue} intersected with {Red} is empty. Removing and preserving filters has its own chapter, so this is only a preview.
Limits of boolean filter arguments
A boolean filter argument must refer to a single column of a single table. It also cannot call a measure. A condition such as [Sales Amount] > 1000 has to be written with FILTER over a table. Iterating a table with a measure inside depends on context transition, which comes later.
Looking at the filter context
You cannot see the filter context in the report, but DAX can report on it. These functions are useful when you debug a surprising number.
| Function | Answers |
|---|---|
| `VALUES ( column )` | Which values of the column remain in the current filter context |
| `SELECTEDVALUE ( column, alternate )` | The single remaining value, or the alternate when there are zero or several |
| `HASONEVALUE ( column )` | Whether exactly one value of the column remains |
| `ISFILTERED ( column )` | Whether the column is directly filtered |
This measure shows which colors the current cell is filtered to:
Selected Colors =
IF (
ISFILTERED ( Product[Color] ),
CONCATENATEX (
VALUES ( Product[Color] ),
Product[Color],
", ",
Product[Color]
),
"No color filter"
)Put it in a card with no slicers and it shows "No color filter". Select Red and Blue in a slicer and it shows "Blue, Red". In the grand total row of the matrix above, it shows "No color filter", which confirms that the total row carries no Color filter.
ISFILTERED is true only when the column itself is filtered directly. A column can also be restricted indirectly, because a filter on a related table removes rows from its table. In that case the column is cross-filtered but not filtered, and ISFILTERED returns false. VALUES still shows the reduced list in both cases.
Common errors
- Expecting totals to add up. The total row is its own evaluation. If it differs from the sum of the rows, the measure is not additive, or the rows hide a filter you did not account for.
- A blank cell where you expected a number. Check for two filters on the same column that have no value in common, such as a slicer on
Colorplus aCALCULATEthat usesKEEPFILTERSor a row header with a different value. - A slicer that seems to be ignored. A
CALCULATEfilter on the same column replaces the slicer's selection. The slicer is not broken. The measure overrides it. - The same value in every row. The column on the rows has no relationship to the table that the measure aggregates, so nothing filters that table. The relationship chapters explain this.
- A measure inside a boolean filter argument. DAX rejects it. Use
FILTERover a table instead. - Thinking of the filter context as a row. The filter context restricts the available rows. Reading values from one specific row is a different mechanism, called row context, covered in the next chapter.
Exercise
A matrix shows Product[Color] on the rows. A slicer on Product[Color] has Red and Blue selected. The matrix uses the measure Red Sales = CALCULATE ( [Sales Amount], Product[Color] = "Red" ). What do the Blue row and the Total row show?
Show answer
Both show the same number as the Red row, which is total red sales. In the Blue row, the row header filters Color to Blue, and the slicer filters it to {Red, Blue}. CALCULATE replaces every existing filter on Product[Color] with Color = Red. The Total row has only the slicer filter, and that is replaced in the same way. The Black row does not appear, because the slicer removes Black from the colors the visual lists.
Exercise
Rewrite Red Sales so that the Blue row is blank and the Red row shows red sales, while the slicer from the previous exercise stays in effect. Then state the filter context of the Blue row.
Show answer
Wrap the filter in KEEPFILTERS: CALCULATE ( [Sales Amount], KEEPFILTERS ( Product[Color] = "Red" ) ). KEEPFILTERS intersects the new filter with the existing one instead of replacing it. In the Blue row, the existing filter on Color is Blue (row header) intersected with {Red, Blue} (slicer), which gives {Blue}. Intersecting {Blue} with {Red} leaves nothing, so the cell is blank.
Exercise
Sales Amount for 2025 is 600 in total and the three color rows show 250, 200, and 150. A colleague writes a measure Distinct Customers = DISTINCTCOUNT ( Sales[CustomerKey] ). The three color rows show 40, 35, and 30, but the Total row shows 80, not 105. Is the Total row wrong?
Show answer
No. The Total row is a separate evaluation with no Color filter, only Year = 2025. DISTINCTCOUNT counts each customer once in that context. A customer who bought in more than one color is counted in each color row but only once in the total, so the total (80) is lower than the sum of the rows (105). Distinct counts are not additive.