Power Pivot & DAX course · Lesson 8 of 16

Removing filters: ALL, ALLEXCEPT, ALLSELECTED and REMOVEFILTERS

Percent of total, of category and of selection in DAX: how ALL, ALLEXCEPT, ALLSELECTED and REMOVEFILTERS remove filters inside CALCULATE.

Intermediate 20 min read

Shares and percentages are where reports get interesting: what share of revenue does each product bring, how big is a region within its segment, what fraction of the selected items is this one? Each of these needs a denominator that ignores some of the filters of the current cell. DAX has a family of functions for removing filters: ALL, ALLEXCEPT, ALLSELECTED and REMOVEFILTERS. They are almost always used as filter arguments of CALCULATE: changing the filter context in DAX.

ALL: remove filters from a table or columns

DAX
Revenue := SUM ( Sales[Amount] )
Revenue All Products := CALCULATE ( [Revenue], ALL ( Products ) )
% of Total := DIVIDE ( [Revenue], [Revenue All Products] )
ALL ( Products ) removes every filter on the Products table.

In a PivotTable with Category and Product on rows, the Mouse row has the filters Category = Accessories and Product = Mouse. Inside Revenue All Products, ALL ( Products ) throws both away, so the measure returns the revenue of all products. Dividing the row's revenue by that number gives its share of the total.

ALL can also take one or more columns of the same table. ALL ( Products[Product] ) removes only the filter on the Product column and keeps the Category filter, which gives a share of the parent category:

DAX
% of Category := DIVIDE ( [Revenue], CALCULATE ( [Revenue], ALL ( Products[Product] ) ) )
Share of the product within its category.
ABCDE
1CategoryProductRevenue% of Total% of Category
2AccessoriesKeyboard3855.8%51.7%
3Mouse3605.4%48.3%
4Accessories Total74511.2%100.0%
5ComputersLaptop285042.9%57.6%
6Tablet210031.6%42.4%
7Computers Total495074.5%100.0%
8DisplaysMonitor94514.2%100.0%
9Displays Total94514.2%100.0%
10Grand Total6640100.0%100.0%

Category and Product on rows (tabular layout with subtotals). Percentages with 1 decimal.

Check the Laptop row: 2,850 ÷ 6,640 = 42.9% of the total, and 2,850 ÷ 4,950 = 57.6% of the Computers category. On subtotal rows there is no Product filter to remove, so % of Category is 100%.

Watch out. ALL ( Products ) removes filters on Products only. A slicer on Customers[Region] or on a date column still applies. If you want a share of the grand total of everything, list each table: ALL ( Products ), ALL ( Customers ), or remove filters from the fact table with ALL ( Sales ), which also clears filters coming from every dimension related to it.

ALLEXCEPT: remove all filters except some

ALLEXCEPT ( table, column1, column2, ... ) removes every filter on the table except those on the listed columns. Suppose we want each region's share of its customer segment. The Region filter must go, the Segment filter must stay:

DAX
Segment Revenue := CALCULATE ( [Revenue], ALLEXCEPT ( Customers, Customers[Segment] ) )
% of Segment := DIVIDE ( [Revenue], [Segment Revenue] )
Keeps only the Segment filter on Customers.
ABCDE
1RegionSegmentRevenueSegment Revenue% of Segment
2EastBusiness807414519.5%
3NorthConsumer24952495100.0%
4SouthBusiness1280414530.9%
5WestBusiness2058414549.7%
6Grand Total66406640100.0%

Region and Segment on rows (tabular layout, subtotals off). Each region belongs to one segment in this data.

East, South and West are all Business customers, whose revenue totals 4,145; North is the only Consumer region, so it is 100% of its segment. ALLEXCEPT is handy when a dimension has many columns and you want to keep just one or two; with ALL you would have to list every column to remove.

ALLSELECTED: respect the user's selection

ALL ignores slicers too, which is not always what a reader expects. If a slicer on Category is set to Accessories and Computers, a reader might want each product's share of what is selected, so that the visible rows add up to 100%. ALLSELECTED removes the filters coming from the PivotTable's rows and columns but keeps the ones coming from outside them (slicers and report filters):

DAX
% of All := DIVIDE ( [Revenue], CALCULATE ( [Revenue], ALL ( Products ) ) )
% of Selected := DIVIDE ( [Revenue], CALCULATE ( [Revenue], ALLSELECTED ( Products ) ) )
Two denominators: all products, or only the selected ones.
ABCD
1ProductRevenue% of All% of Selected
2Keyboard3855.8%6.8%
3Laptop285042.9%50.0%
4Mouse3605.4%6.3%
5Tablet210031.6%36.9%
6Grand Total569585.8%100.0%

Products[Product] on rows, Category slicer = Accessories and Computers.

The selected categories bring 5,695 of the 6,640 total, so % of All adds up to 85.8% at the bottom, while % of Selected adds up to 100%. Which one is right depends on the question you are answering; many reports show both.

Note. ALLSELECTED is the most complex function of the family: it restores the filter context that existed outside the visual, and it behaves differently inside iterators. Use it as a denominator in simple percent-of-visible-total measures like this one and it will behave as expected.

REMOVEFILTERS: a clearer name for ALL

DAX
% of Total := DIVIDE ( [Revenue], CALCULATE ( [Revenue], REMOVEFILTERS ( Products ) ) )
Same result as ALL ( Products ) as a CALCULATE filter.

When ALL is used as a filter argument of CALCULATE, it does not return anything useful; it just removes filters. REMOVEFILTERS was added to DAX to say exactly that. It accepts a table or columns, just like ALL, but it can only be used as a CALCULATE modifier, never as a table to iterate. It is available in current Microsoft 365 builds; if an older Excel version reports that the function is unknown, use ALL instead, which works everywhere.

ALL as a table

Outside CALCULATE, ALL returns a table: all rows of a table, or the distinct values of the listed columns, regardless of filters. That is useful in iterators and counts:

DAX
Product Count All := COUNTROWS ( ALL ( Products ) )
Category Count := COUNTROWS ( ALL ( Products[Category] ) )
Return 5 and 3 in every cell.

You will use exactly this pattern for ranking in Iterators in DAX: SUMX, AVERAGEX, MAXX and RANKX, where RANKX ( ALL ( Products[Product] ), [Revenue] ) compares each product with all the others.

Choosing the right function

You want the denominator to…Use
Ignore every filter on a tableALL ( Table ) or REMOVEFILTERS ( Table )
Ignore the filter on one column onlyALL ( Table[Column] )
Keep one or two columns' filters, drop the restALLEXCEPT ( Table, Table[Col1], ... )
Respect slicers but ignore rows and columnsALLSELECTED ( Table )
Ignore all dimensions at onceALL ( FactTable )
Tip. Always wrap share calculations in DIVIDE. If a slicer selection produces an empty denominator, DIVIDE returns blank instead of an error or Infinity (Variables, DIVIDE and error handling in DAX).

Check yourself

1. Which denominator gives each product's share of its category?

2. A Region slicer is set to North. Does CALCULATE ( [Revenue], ALL ( Products ) ) still respect it?

3. What does ALLEXCEPT ( Customers, Customers[Segment] ) keep?

4. With a Category slicer selecting two categories, which measure makes the visible products add up to 100%?

5. Where can REMOVEFILTERS be used?