Sub topic 6
Removing Filters with REMOVEFILTERS, ALL and ALLEXCEPT
This chapter assumes you can write basic DAX measures, you have a star-schema model with one-to-many relationships, and you know that CALCULATE evaluates an expression in a modified filter context. The previous chapter showed that a Boolean filter on a column replaces any existing filter on that column. Here you will learn to remove filters instead of replacing them. This is the technique behind percent-of-total, share-of-category and "all time" measures.
Why you need to remove filters
A measure like [Total Sales] responds to every slicer, row header and column header in the report. That is usually what you want. Some calculations need a reference value that ignores part of that selection. A share needs a denominator that stays fixed while the numerator follows the selection.
CALCULATE can do this because its filter arguments can be filter modifiers. A modifier does not add a condition. It changes the filter context that already exists, for example by clearing a column, a table or every filter at once.
Total Sales = SUM ( Sales[Amount] )REMOVEFILTERS
REMOVEFILTERS is a CALCULATE modifier that clears filters. It accepts three kinds of arguments:
- A column, such as
'Product'[Category]. It clears the filter on that column. - Several columns, such as
'Product'[Category], 'Product'[Color]. It clears the filter on each listed column. - A table, such as
'Product'. It clears filters on every column of that table. - No argument. It clears all filters from every table in the model.
Here is the share-of-category measure:
Sales Share of Category =
DIVIDE (
[Total Sales],
CALCULATE ( [Total Sales], REMOVEFILTERS ( 'Product'[Category] ) )
)The numerator, [Total Sales], is evaluated in the current filter context. The denominator is wrapped in CALCULATE, which removes the filter on 'Product'[Category] for that part only. If a visual shows one row per category, each row divides its own sales by the sales of all categories. The result is the category's share of the total.
DIVIDE returns blank when the denominator is zero or blank, so you avoid a division error.
Only the named columns are cleared
Removing the filter on 'Product'[Category] does not touch other filters. Suppose the report has a slicer on 'Date'[Year] set to 2025. The denominator above still covers only 2025, because nothing removed the year filter. This is usually the behavior you want, and it is a common source of confusion when people expect "total" to mean "everything".
ALL as a modifier
ALL is older than REMOVEFILTERS and does the same job when it is used as a CALCULATE argument. These two measures return the same value:
Sales All Categories (ALL) =
CALCULATE ( [Total Sales], ALL ( 'Product'[Category] ) )
Sales All Categories (REMOVEFILTERS) =
CALCULATE ( [Total Sales], REMOVEFILTERS ( 'Product'[Category] ) )The difference is that ALL is also a table function. When you use it outside the filter arguments of CALCULATE, for example as the first argument of an iterator, it returns a table with all the distinct values or rows, and it does not act as a modifier.
Sales Per Category Average =
AVERAGEX (
ALL ( 'Product'[Category] ),
[Total Sales]
)Here ALL returns the list of categories, ignoring filters on the category column, and AVERAGEX iterates over that list. Because ALL has two roles, a reader cannot always tell what it is doing at first glance. REMOVEFILTERS can only be used to remove filters, so it states the intent more clearly. Prefer REMOVEFILTERS when you only want to clear filters. Use ALL when you need the table of values.
| Function | Used in CALCULATE filter arguments | Used where a table is expected |
|---|---|---|
| `REMOVEFILTERS` | Clears filters | Not allowed as a table source |
| `ALL` | Clears filters | Returns the table or column values with no filters |
| `ALLEXCEPT` | Clears filters on a table except for the listed columns | Returns the table with filters kept only on the listed columns |
What happens when you remove a filter from a column
A filter context is a set of filters on columns. When CALCULATE removes the filter on a column, the column goes back to showing all of its values. Filters from other columns still apply. Consider the following visual state.
- Rows:
'Product'[Category] - Slicer:
'Date'[Year]= 2025 - Slicer:
'Product'[Color]= Red
For the Bikes row, [Total Sales] sees three filters: category Bikes, year 2025 and color Red. Applying REMOVEFILTERS ( 'Product'[Category] ) leaves two: year 2025 and color Red. The result is red sales for 2025 across all categories.
Removing filters from a whole table
If you pass a table name, every column of that table is cleared. This is useful when several columns of a dimension can be filtered, such as category, subcategory, color and product name, and you want the denominator to ignore all of them.
Sales Share of All Products =
DIVIDE (
[Total Sales],
CALCULATE ( [Total Sales], REMOVEFILTERS ( 'Product' ) )
)Clearing the 'Product' table removes the filters on that table. Because filters travel from dimension tables to fact tables through relationships, the Sales table is no longer restricted by any product selection. Filters on 'Date' and other dimensions remain.
Removing every filter
With no argument, REMOVEFILTERS clears all filters from all tables.
Grand Total Sales =
CALCULATE ( [Total Sales], REMOVEFILTERS () )This returns the grand total regardless of any slicer or row header. It is occasionally right, for example for a "percent of everything" card. It is often too strong. A user who filters the report to one year probably expects the denominator to respect that year. When in doubt, name the columns or tables you want to clear.
ALLEXCEPT
ALLEXCEPT takes a table and a list of columns from that table. It clears all filters on the table except the listed columns, which keep their filters.
Sales Share Within Year =
DIVIDE (
[Total Sales],
CALCULATE (
[Total Sales],
ALLEXCEPT ( 'Date', 'Date'[Year] )
)
)If a visual shows months in rows and a slicer selects year 2025, the denominator removes the month filter and keeps the year filter. Each month is then shown as a share of its year.
The same result with REMOVEFILTERS and VALUES
You can express the intent of ALLEXCEPT in another way. Clear the whole table, then reapply the filter you want to keep.
Sales Share Within Year (alt) =
DIVIDE (
[Total Sales],
CALCULATE (
[Total Sales],
REMOVEFILTERS ( 'Date' ),
VALUES ( 'Date'[Year] )
)
)VALUES ( 'Date'[Year] ) returns the years that were visible in the original filter context. CALCULATE evaluates its filter arguments in the original context before it applies them, so VALUES still sees the selected year even though REMOVEFILTERS clears the table. The next chapters on evaluation order explain this in detail.
The alternative is longer, but it works in cases where ALLEXCEPT is too limited. For instance, it lets you keep a filter that was applied through a relationship rather than directly on the column.
An ALLEXCEPT gotcha
ALLEXCEPT works on the columns of one table. It looks at filters on the columns you list and keeps those. A filter applied to a different column of the same table is removed, even if that other column is related to the one you kept. Keep in mind too that ALLEXCEPT is a table function in origin. Use it as a CALCULATE argument to clear filters, as above.
Removing filters from a column in a different table
Filters flow from the one side to the many side of a relationship. If you clear a filter on 'Product'[Category], you remove the filter that came from that column. If another column on a different dimension also restricts Sales, that restriction stays.
Suppose Sales can be filtered by 'Customer'[Country] and by 'Product'[Category]. The following measure clears only the product filter:
Sales All Products =
CALCULATE ( [Total Sales], REMOVEFILTERS ( 'Product' ) )A selected country still applies. If you want to clear both, list both tables:
Sales All Products and Customers =
CALCULATE (
[Total Sales],
REMOVEFILTERS ( 'Product' ),
REMOVEFILTERS ( 'Customer' )
)Interaction with other filter arguments
Filter modifiers and ordinary filters can appear in the same CALCULATE. A modifier clears filters first, and the other arguments are then applied to the cleared context. Together they behave as follows.
Red Sales All Categories =
CALCULATE (
[Total Sales],
REMOVEFILTERS ( 'Product'[Category] ),
'Product'[Color] = "Red"
)The category filter is cleared, and the color filter is set to red, replacing any existing color selection. The result is red sales in all categories, restricted only by filters on other tables such as the date.
Note that a Boolean argument such as 'Product'[Color] = "Red" already replaces any existing filter on 'Product'[Color]. You do not need REMOVEFILTERS ( 'Product'[Color] ) in addition. Adding it is harmless but noisy.
Common mistakes
- Clearing too much.
REMOVEFILTERS ()with no argument removes date filters too. A "percent of total" card then ignores the year slicer. - Clearing too little. Removing only
'Product'[Category]leaves filters on subcategory or product name in place. If the visual shows products, the denominator is still restricted to the product on that row. Clear the table instead. - Using a variable for the denominator after the change. A variable computed before CALCULATE does not change when CALCULATE removes filters. Put the CALCULATE expression inside the variable definition, not around it.
- Expecting ALL to change a total outside CALCULATE.
ALLonly acts as a modifier inside the filter arguments of CALCULATE or CALCULATETABLE.
The following measure shows the correct way to use a variable here:
Sales Share of Category (variables) =
VAR CurrentSales = [Total Sales]
VAR CategorySales =
CALCULATE ( [Total Sales], REMOVEFILTERS ( 'Product'[Category] ) )
RETURN
DIVIDE ( CurrentSales, CategorySales )Each variable is evaluated once, in the context where it is defined. CategorySales contains its own CALCULATE, so the removal happens inside the variable.
Choosing between the functions
- Use
REMOVEFILTERSwith columns or a table when you want to clear a filter and nothing else. - Use
ALLEXCEPTwhen it is easier to name the columns to keep than the columns to clear. - Use
ALLwhen you need a table of values to iterate over, or when you maintain older code that already uses it. - Use
REMOVEFILTERS ()with no argument only when you really want the grand total.
Exercise
A matrix shows 'Product'[Category] in rows and has a slicer on 'Date'[Year] set to 2025. You write CALCULATE ( [Total Sales], REMOVEFILTERS ( 'Product'[Category] ) ). What does the measure return in the Bikes row, and which filter is still active?
Show answer
It returns the 2025 sales of all categories together, the same value on every row. The filter on 'Date'[Year] is still active because REMOVEFILTERS cleared only the Category column. If the formula used REMOVEFILTERS () with no argument, the year filter would be cleared too and the result would cover all years.
Exercise
A matrix shows 'Date'[Month] in rows, with a slicer on 'Date'[Year] set to 2025. Write a measure that gives each month's sales as a share of the selected year's sales, using ALLEXCEPT.
Show answer
DIVIDE ( [Total Sales], CALCULATE ( [Total Sales], ALLEXCEPT ( 'Date', 'Date'[Year] ) ) ). ALLEXCEPT clears the filter on Month and every other column of 'Date' but keeps the filter on Year, so the denominator is the total for 2025.