Sub topic 5
Boolean filters replace filters on the same column
This chapter assumes you can write basic DAX measures and calculated columns. It also assumes you have a star-schema model with one-to-many relationships and know how slicers, rows and columns filter a measure. You should already know that CALCULATE evaluates an expression in a modified filter context. Here we look at the most common kind of modification: a Boolean filter argument, and the rule that it replaces any existing filter on the column it mentions.
The base measure
All examples use one measure. Its result depends entirely on the filter context it is evaluated in.
Total Sales = SUM ( Sales[Amount] )In a matrix with 'Product'[Color] on the rows, each row shows the sales for that color. In a card with no slicers, the measure shows sales for every color. The expression is the same in both cases. Only the filter context differs.
What a Boolean filter argument is
A Boolean filter argument is a logical expression that compares a single column to a value. CALCULATE accepts it as a filter.
Red Sales =
CALCULATE (
[Total Sales],
'Product'[Color] = "Red"
)The argument 'Product'[Color] = "Red" looks like a row-by-row test. It is not evaluated that way. DAX treats it as shorthand for a table of allowed values:
Red Sales Expanded =
CALCULATE (
[Total Sales],
FILTER (
ALL ( 'Product'[Color] ),
'Product'[Color] = "Red"
)
)ALL ( 'Product'[Color] ) returns every distinct color, ignoring the current filter on that column. FILTER then keeps only the rows where the color is Red. The result is a one-row table with the value "Red". CALCULATE uses that table as a filter on 'Product'[Color].
This expansion explains the central rule of the chapter.
The replacement rule
When a Boolean filter argument targets a column, CALCULATE removes any existing filter on that column from the filter context. It then applies the new filter. The new filter replaces the old one. It does not combine with it.
Suppose a report has a slicer that selects Blue. Without CALCULATE, [Total Sales] returns blue sales. [Red Sales] returns red sales anyway. The slicer's filter on 'Product'[Color] is overwritten by the Boolean argument.
The replacement happens per column, not per table. Consider a slicer on 'Product'[Category] that selects Bikes, and the [Red Sales] measure. The Boolean argument names only 'Product'[Color]. The filter on 'Product'[Category] stays in place. The measure returns red sales within Bikes.
| Existing filter | CALCULATE argument | Resulting filter |
|---|---|---|
| Color = Blue | Color = "Red" | Color = Red |
| Category = Bikes | Color = "Red" | Category = Bikes and Color = Red |
| No filter on Color | Color = "Red" | Color = Red |
| Color = Blue or Red | Color = "Red" | Color = Red |
The last row shows that the new filter does not care what the old filter was. The old filter can be a single value, several values, or absent.
Seeing the rule in a matrix
Put 'Product'[Color] on the rows of a matrix with [Total Sales] and [Red Sales] side by side. Row filters on Color apply to [Total Sales] as usual. For [Red Sales], CALCULATE replaces each row's color filter with Red. Every row therefore shows the same number: total red sales.
This surprises many learners. The measure appears to ignore the rows. It does not ignore them by accident. The Boolean argument targeted the same column the rows filter, so the row filter was overwritten.
If you place 'Product'[Category] on the rows instead, the results differ. Each row has a filter on Category, and the Boolean argument does not touch it. Each row shows red sales for that category.
Using several Boolean arguments
You can pass more than one filter argument. Arguments on different columns combine with AND.
Red Bike Sales =
CALCULATE (
[Total Sales],
'Product'[Color] = "Red",
'Product'[Category] = "Bikes"
)Each argument replaces the filter on its own column. The two new filters then apply together.
Two arguments on the same column also combine, because each becomes a filter table and the filters intersect. The following measure returns blank when no row can satisfy both conditions, as no color is both Red and Blue.
Red And Blue Sales =
CALCULATE (
[Total Sales],
'Product'[Color] = "Red",
'Product'[Color] = "Blue"
)To express "Red or Blue", use one argument with an || operator or the IN operator:
Red Or Blue Sales =
CALCULATE (
[Total Sales],
'Product'[Color] IN { "Red", "Blue" }
)This is still a single filter on one column. It replaces the existing filter on 'Product'[Color] with a two-value filter.
Restrictions on Boolean arguments
A Boolean filter argument must reference exactly one column. It must be an expression that DAX can turn into a filter on that column. That is why these forms work:
'Product'[Color] = "Red"Sales[Quantity] > 2'Product'[Color] IN { "Red", "Blue" }'Date'[Year] = 2025 || 'Date'[Year] = 2026
The last form works because both sides name the same column. An expression that compares two different columns does not work as a Boolean filter argument:
Invalid Filter =
CALCULATE (
[Total Sales],
Sales[Quantity] > Sales[Price]
)DAX rejects this, because it cannot reduce the test to one column. Use a table filter such as FILTER ( Sales, Sales[Quantity] > Sales[Price] ) for that case. Table filters are covered in a later chapter.
A Boolean argument also cannot contain a measure or a nested CALCULATE. A condition like Sales[Amount] > [Average Sale] fails for this reason. Compute the threshold in a variable first and compare against the variable:
Above Average Line Sales =
VAR Threshold = AVERAGE ( Sales[Amount] )
RETURN
CALCULATE (
[Total Sales],
Sales[Amount] > Threshold
)The variable is evaluated before CALCULATE runs. It holds a plain value, so the Boolean argument can compare the column to it.
Why the Boolean form replaces filters
The replacement behavior follows from the expansion shown earlier. The expanded form uses ALL ( 'Product'[Color] ) as the table being filtered. ALL removes the filter on that column while it builds the candidate values. When CALCULATE applies the resulting filter, the only filter on 'Product'[Color] is the new one.
It helps to think of CALCULATE as doing two things for each Boolean argument. It clears the filter on the column. It then sets the new filter. In the Topic's later chapters you will see that other argument types, such as table arguments built with FILTER over a whole table, do not clear filters in the same way. That difference is the reason the Boolean form is predictable and often preferred for simple conditions.
Keeping the existing selection
Sometimes replacement is not what you want. You may want red sales only if the user has not excluded red. KEEPFILTERS changes the behavior from replace to intersect.
Red Sales Within Selection =
CALCULATE (
[Total Sales],
KEEPFILTERS ( 'Product'[Color] = "Red" )
)With a slicer that selects Blue, the existing filter is Blue and the new filter is Red. Their intersection is empty, so the measure returns blank. With a slicer that selects Red and Blue, the intersection is Red, and the measure returns red sales. KEEPFILTERS is covered in detail in its own chapter. It is mentioned here so you can recognize the contrast.
Common mistakes with Boolean filters
- Expecting a slicer to narrow the result. A measure like
[Red Sales]ignores a slicer on color. If a report must respect the slicer, useKEEPFILTERSor do not filter that column in CALCULATE. - Putting the filtered column on the rows and expecting different values. Every row shows the same number, as described above.
- Using a measure in a Boolean argument. Move the measure into a variable that holds a value.
- Comparing two columns. Use a table filter instead.
- Assuming the filter applies to the whole table. It applies to the single named column. Other columns keep their filters.
A short worked comparison
Assume the slicer selects Blue, and the data holds these sales:
| Color | Amount |
|---|---|
| Red | 100 |
| Blue | 60 |
| Green | 40 |
The measures return these values.
| Measure | Result | Reason |
|---|---|---|
| `[Total Sales]` | 60 | The slicer filters Color to Blue |
| `[Red Sales]` | 100 | The Boolean argument replaces Blue with Red |
| `[Red Sales Within Selection]` | blank | Red intersected with Blue is empty |
| `Red Or Blue Sales` | 160 | The filter is replaced with Red and Blue |
Work through each row yourself before checking the reason. If a prediction differs from the table, find which filter you thought remained in place.
Exercise
A matrix has 'Product'[Category] on the rows and a slicer on 'Product'[Color] set to Green. The measure is Red Sales = CALCULATE ( [Total Sales], 'Product'[Color] = "Red" ). What does each category row show, and why?
Show answer
Each row shows red sales for that category. The row's filter on Category is not touched, because the Boolean argument names only 'Product'[Color]. The Boolean argument removes the slicer's Green filter on Color and replaces it with Red.
Exercise
You want a measure that returns sales for red products only when Red is part of the user's color selection, and blank otherwise. Which change to Red Sales achieves this, and what does it return if the slicer selects Blue and Green?
Show answer
Wrap the Boolean argument in KEEPFILTERS: CALCULATE ( [Total Sales], KEEPFILTERS ( 'Product'[Color] = "Red" ) ). With Blue and Green selected, the intersection of {Blue, Green} and {Red} is empty, so the measure returns blank.
Exercise
Why does CALCULATE ( [Total Sales], Sales[Quantity] > Sales[Price] ) fail, and what is a working alternative?
Show answer
A Boolean filter argument must reference a single column so DAX can turn it into a filter on that column. This test references two columns. Use a table filter instead: CALCULATE ( [Total Sales], FILTER ( Sales, Sales[Quantity] > Sales[Price] ) ).