ALL, ALLEXCEPT and REMOVEFILTERS in DAX

How ALL, ALLEXCEPT, REMOVEFILTERS and ALLNOBLANKROW remove filters in DAX, the difference between using them as CALCULATE modifiers and as table functions, percent of total and percent of parent examples, and the traps of ALLEXCEPT with columns from other tables.

Short answer: these functions remove filters. REMOVEFILTERS only removes filters, inside CALCULATE: from a table, from columns, or from everything. ALL does the same as a CALCULATE modifier, and can also return a table of all rows or all distinct values, ignoring filters, which you can iterate or count. ALLEXCEPT ( table, col1, ... ) removes all filters from a table except those on the listed columns. ALLNOBLANKROW is like ALL without the blank row that unmatched keys add. Microsoft recommends REMOVEFILTERS when you only want to remove filters.

"Percent of total" is the first measure most people write after a sum, and it needs one of these: the total is the same revenue with the filters removed.

What does each function do?

FunctionAs CALCULATE modifierAs table function
REMOVEFILTERS ( table or columns )removes those filtersnot available
REMOVEFILTERS ( )removes all filtersnot available
ALL ( table )removes all filters on the tableall rows of the table
ALL ( col1, col2 )removes filters on these columnsdistinct combinations of these columns
ALLEXCEPT ( table, cols )removes all filters on the table except on colsall rows, keeping those filters
ALLNOBLANKROW ( table or cols )as ALL, without the blank rowrows without the blank row
Removing filters in DAX

How do you calculate shares?

-- percent of all products, whatever is filtered on Product
% of All Products =
DIVIDE ( [Revenue], CALCULATE ( [Revenue], REMOVEFILTERS ( 'Product' ) ) )

-- percent of the category (parent): remove the product filter, keep category
% of Category =
DIVIDE (
    [Revenue],
    CALCULATE ( [Revenue], REMOVEFILTERS ( 'Product'[Product] ) )
)

-- the same with ALLEXCEPT
% of Category 2 =
DIVIDE (
    [Revenue],
    CALCULATE ( [Revenue], ALLEXCEPT ( 'Product', 'Product'[Category] ) )
)
Category, ProductRevenue% of All Products% of Category
Bikes, Mountain-20090031%43%
Bikes, Road-1501,20041%57%
Accessories, Helmet50017%61%
Accessories, Bottle32011%39%
Total2,920100%100%
A matrix of category and product with the three shares

Filters from other tables (year, region) stay in place in all three measures. REMOVEFILTERS ( 'Product'[Product] ) keeps other Product columns, such as a Color slicer, while ALLEXCEPT ( 'Product', 'Product'[Category] ) removes the Color filter too.

When do you need ALL as a table?

-- number of products, whatever is filtered
Product Count All = COUNTROWS ( ALL ( 'Product' ) )

-- rank among all products, not just the visible ones
Product Rank = RANKX ( ALL ( 'Product'[Product] ), [Revenue] )

-- average monthly revenue across all months of the year in context
Avg Month = AVERAGEX ( ALL ( 'Date'[Month] ), [Revenue] )

REMOVEFILTERS cannot be used here: it does not return a table.

What is the blank row?

When a fact table holds keys missing from a dimension, the dimension gets a virtual blank row that collects them. ALL ( 'Product' ) includes it; ALLNOBLANKROW ( 'Product' ) does not. COUNTROWS ( ALL ( 'Product' ) ) can therefore be one more than the real number of products.

What goes wrong?

  • ALLEXCEPT on the fact table. ALLEXCEPT ( Sales, 'Product'[Category] ) removes the filters of every table that filters Sales (dates, customers, regions) except the listed column, which is rarely the intent; use REMOVEFILTERS on the dimension columns you want gone.
  • ALLEXCEPT removes more than expected. It also removes filters on columns you forgot to list, such as Color.
  • ALL ( Sales ) in a measure. Removing filters from the fact table removes the effect of all dimension filters for that calculation; usually you want REMOVEFILTERS on one dimension.
  • Ignoring slicers. % of All Products ignores a product slicer too; use ALLSELECTED for "of what the reader selected".

Where can you check this?

Where do you start?

Write % of All Products and % of Category and put them in a matrix by category and product. ALLSELECTED covers the share of what the reader selected.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.