Sub topic 7
ALLEXCEPT: clearing all filters on a table except chosen columns
This chapter assumes you can write basic measures with SUM and COUNTROWS. It also assumes you know how CALCULATE changes filter context, and that you have seen ALL and REMOVEFILTERS clear filters from a table. Here you will learn what ALLEXCEPT clears, what it keeps, and when its "keep" rule gives the wrong answer.
What ALLEXCEPT does
ALLEXCEPT removes every filter from a table, except the filters on the columns you list. Its syntax is:
ALLEXCEPT ( <table>, <column> [, <column> [, ...]] )Read it as "clear the whole table, but spare these columns." The first argument is a table. The remaining arguments are columns of that same table.
You can think of the other functions this way:
REMOVEFILTERS ( 'Product' )clears all columns ofProduct.REMOVEFILTERS ( 'Product'[Color] )clears one column.ALLEXCEPT ( 'Product', 'Product'[Category] )clears every column ofProductexceptCategory.
The third form is the reason ALLEXCEPT exists. It lets you name the one or two columns to keep without listing every other column of a wide table.
The standard example: percent of category
This measure divides the current sales by the sales of the current category:
Sales % of Category =
DIVIDE (
[Total Sales],
CALCULATE ( [Total Sales], ALLEXCEPT ( 'Product', 'Product'[Category] ) )
)[Total Sales] is SUM ( Sales[Amount] ). The numerator runs in the filter context of the visual. The denominator runs after ALLEXCEPT has cleared every Product filter except the one on Category. The result is the sales of the whole category, whichever subcategory, color, or product the current row shows.
Here is the arithmetic for a small model. The visual has Category and Color on its rows, and no slicers.
| Category | Color | Total Sales | Sales % of All Products | Sales % of Category |
|---|---|---|---|---|
| Audio | Red | 100 | 10% | 25% |
| Audio | Blue | 300 | 30% | 75% |
| Video | Red | 200 | 20% | 33.3% |
| Video | Blue | 400 | 40% | 66.7% |
For the Audio / Red row, the filter context holds Category = Audio and Color = Red. ALLEXCEPT drops the Color filter and keeps Category = Audio. The denominator is 100 + 300 = 400, so the row shows 100 / 400 = 25%.
Sales % of All Products is the measure from the previous chapter. It uses REMOVEFILTERS ( 'Product' ), so its denominator is 1,000 on every row.
Where the filters come from
ALLEXCEPT clears the filters that exist in the current filter context. Those filters can come from several places:
- A field on a visual's rows or columns, such as
Categoryin a matrix. - A slicer or a filter on the report page.
- A filter argument in an enclosing
CALCULATE. - A hierarchy level, where a parent row filters the child level.
Suppose a matrix has the hierarchy Category > Subcategory on its rows. On a Subcategory row, the context holds filters on both columns. ALLEXCEPT on Category drops the subcategory filter and keeps the category filter. On a Category row, there is no subcategory filter to remove, so the numerator and denominator agree and the result is 100%.
On the grand total row, no Category filter exists. There is nothing to keep, so the denominator is all sales and the result is 100%.
Keeping more than one column
You can list several columns to keep. This measure computes each product's share of its category within one brand:
Sales % of Brand in Category =
DIVIDE (
[Total Sales],
CALCULATE (
[Total Sales],
ALLEXCEPT ( 'Product', 'Product'[Category], 'Product'[Brand] )
)
)Both the Category and Brand filters survive. Filters on every other Product column are cleared.
ALLEXCEPT only touches one table
ALLEXCEPT clears filters on the table you name. It does not clear filters on other tables, even when relationships link them to that table.
Suppose a report has a Date slicer for 2025 and a matrix with Product[Category] and Product[Color] on its rows. The Date filter stays in effect inside the denominator. So Sales % of Category shows each row's share of its category's 2025 sales. This is usually what you want. To also ignore the date filter, add a second modifier:
Sales % of Category All Time =
DIVIDE (
[Total Sales],
CALCULATE (
[Total Sales],
ALLEXCEPT ( 'Product', 'Product'[Category] ),
REMOVEFILTERS ( 'Date' )
)
)CALCULATE accepts several filter modifiers, and each one acts on its own table.
The gotcha: slicers on columns you did not list
ALLEXCEPT removes slicer filters on unlisted columns, not just filters from visual rows. This catches many people.
Say a page has a Color slicer set to Red. The matrix shows Category and Color. With Sales % of Category, the denominator is the whole category, because Color is not in the keep list. The slicer's filter on Color is removed too.
| Category | Color | Total Sales | Sales % of Category |
|---|---|---|---|
| Audio | Red | 100 | 25% |
| Video | Red | 200 | 33.3% |
A reader might expect 100% on each row, since only red products are visible. The measure gives 25% and 33.3%. It answers "what share of the whole category is red?", not "what share of the visible products is this row?"
If you want the visible-set share, ALLEXCEPT is the wrong tool. Clear only the columns that the visual groups by, and leave the slicer column alone:
Sales % of Visible Category =
DIVIDE (
[Total Sales],
CALCULATE (
[Total Sales],
REMOVEFILTERS ( 'Product'[Subcategory], 'Product'[Product Name] )
)
)The last chapter of this tutorial points to ALLSELECTED, which handles the "share of what the user selected" case more directly.
Which tables and columns are allowed
The call is invalid in these cases:
- The first argument is something like
FILTER ( 'Product', ... ). - A column argument is not a plain column reference.
- A column argument belongs to a different table.
Listing no columns at all is also not supported. The syntax requires at least one. If you want to clear everything, use REMOVEFILTERS ( 'Product' ).
ALLEXCEPT as a table function
Like ALL, ALLEXCEPT returns a table. Inside CALCULATE it works as a filter modifier. Elsewhere you can use it wherever a table is expected. This measure counts the rows of Product in the current category:
Products in Category =
COUNTROWS ( ALLEXCEPT ( 'Product', 'Product'[Category] ) )The result holds the Product rows that remain after all filters except the Category filter are cleared. Whether a row means one product depends on the grain of your Product table. If the table has one row per product, the count is the number of products in the category.
REMOVEFILTERS cannot do this. It returns no table and works only as a CALCULATE modifier.
An equivalent form with VALUES
You can get the same effect by clearing the whole table and re-applying the values you want to keep:
Sales % of Category (VALUES) =
DIVIDE (
[Total Sales],
CALCULATE (
[Total Sales],
REMOVEFILTERS ( 'Product' ),
VALUES ( 'Product'[Category] )
)
)REMOVEFILTERS ( 'Product' ) clears every Product filter. Then VALUES ( 'Product'[Category] ) adds a filter for the categories that were visible in the original context. For ordinary report layouts the result matches ALLEXCEPT.
Choose between them on readability. ALLEXCEPT states "keep Category" in one call. The VALUES form is longer, but it is the pattern to use when you want to keep a filter only after transforming it. An example is keeping the selected values of a column from one table while clearing the table's other filters.
Testing a measure in a query
You can check the numbers before building a visual. This query defines the measures locally and returns one row per category and color. Run it against a model with Sales and Product tables in DAX query view or DAX Studio:
DEFINE
MEASURE Sales[Total Sales] = SUM ( Sales[Amount] )
MEASURE Sales[Sales % of Category] =
DIVIDE (
[Total Sales],
CALCULATE ( [Total Sales], ALLEXCEPT ( 'Product', 'Product'[Category] ) )
)
EVALUATE
SUMMARIZECOLUMNS (
'Product'[Category],
'Product'[Color],
"Total Sales", [Total Sales],
"Sales % of Category", [Sales % of Category]
)
ORDER BY 'Product'[Category], 'Product'[Color]Add a TREATAS filter or an extra argument to SUMMARIZECOLUMNS to simulate a slicer, and watch which rows change.
Common errors with ALLEXCEPT
| Symptom | Likely cause | Fix |
|---|---|---|
| Error that a column cannot be found in the table | The kept column belongs to another table | Use only columns of the table named in the first argument |
| Percentages ignore a slicer you expected to apply | The slicer column is not in the keep list | Add the column to the list, or clear specific columns with `REMOVEFILTERS` |
| Denominator still changes with a date slicer | `ALLEXCEPT` clears one table only | Add `REMOVEFILTERS ( 'Date' )` if the date filter should go |
| Every row shows 100% | The visual groups only by the kept column | Group by a finer column, or check the layout |
| Error when used as a plain table expression in some contexts | A table function was expected and something else was passed | Pass a table name as the first argument |
Decision rule
Use ALLEXCEPT when the requirement reads "ignore every filter on this table except these columns." That includes percent of group, running comparisons within a group, and group-level benchmarks. Use REMOVEFILTERS when you clear whole tables or a few named columns. Use ALL when you need a table as a value, as in COUNTROWS ( ALL ( ... ) ).
Exercise
A matrix has Category and Subcategory on its rows, and a slicer on Product[Brand] is set to Contoso. You write CALCULATE ( [Total Sales], ALLEXCEPT ( 'Product', 'Product'[Category] ) ) as the denominator of a share measure. What does the denominator contain for the row Category = Audio, Subcategory = Speakers?
Show answer
It contains the sales of all Audio products from every brand. ALLEXCEPT keeps the Category filter (Audio). It removes the Subcategory filter and also the Brand slicer, because Brand is not in the keep list.
Exercise
Write a measure named Sales % of Brand that divides [Total Sales] by the sales of the current brand, keeping the Brand filter and clearing all other Product filters. Then say which change would make the denominator ignore a Date slicer as well.
Show answer
Sales % of Brand =
DIVIDE (
[Total Sales],
CALCULATE ( [Total Sales], ALLEXCEPT ( 'Product', 'Product'[Brand] ) )
)
To ignore the Date slicer, add REMOVEFILTERS ( 'Date' ) as another argument of the same CALCULATE. ALLEXCEPT clears filters on the Product table only.
Exercise
Why does ALLEXCEPT ( 'Product', 'Date'[Year] ) fail, and what would you use to keep a Year filter while clearing the Product table?
Show answer
Year is a column of Date, and the columns passed to ALLEXCEPT must belong to the table in its first argument. Use REMOVEFILTERS ( 'Product' ) as the modifier. It clears only Product, so the filter on Date[Year] stays in place without being named.