Preserving Context: ALLSELECTED & Dynamic Denominators
Overview & Learning Objectives
To calculate metrics like "% of Total Sales" or "Store Contribution %", you need a way to ignore the active slicers on a visual and retrieve the Grand Total denominator. In DAX, you remove filters using `ALL()`, `ALLEXCEPT()`, and `REMOVEFILTERS()`. Mastering these functions allows you to strip away visual constraints and compute benchmarks effortlessly.
- Use `ALL()` to strip all filters from a table or column to calculate grand totals.
- Compare `ALL(Table)` with `ALL(Table[Column])`.
- Use `ALLEXCEPT()` and modern `REMOVEFILTERS()` to build dynamic percentage contributions.
Industry Standard
Standard: Modern DAX best practices recommended by Microsoft suggest using `REMOVEFILTERS()` when removing filter context inside `CALCULATE()`, reserving `ALL()` for returning distinct virtual tables.
Real-World Example: FreshBake Artisan Patisserie
FreshBake displays a visual matrix of Sales by Outlet. Analysts need "% of Chain Total" to evaluate store performance.
| Outlet Name | Outlet Sales (₹) | Chain Grand Total (₹) | % of Chain Total |
|---|---|---|---|
| Indiranagar Outlet | 1,50,000 | 5,000,000 | 30.0% |
| Koramangala Outlet | 2,00,000 | 5,000,000 | 40.0% |
| Whitefield Outlet | 1,50,000 | 5,000,000 | 30.0% |
Functions Covered in this Chapter
Here is the definition, exact syntax, parameter breakdown, and real-world business example for each function covered in this chapter:
ALL Function
Definition: Clears all filter context from a column or an entire table, returning all rows regardless of outer slicers or matrix row headers. Can be used as a table expression or a filter modifier.
Grand Total Sales = CALCULATE([Total Sales], ALL(Fact_Sales))
TableOrColumn: The entire table (e.g. `ALL(Dim_Product)`) or specific columns (e.g. `ALL(Dim_Product[Category])`) to clear filters from.
Category % Share = DIVIDE([Total Sales], CALCULATE([Total Sales], ALL(Dim_Product[Category])))ALLEXCEPT Function
Definition: Removes all context filters in the table except filters that have been applied to the specified columns. Perfect for keeping a subcategory or region fixed.
Regional Sales Baseline = CALCULATE([Total Sales], ALLEXCEPT(Dim_Store, Dim_Store[Region]))
Table: The base table whose columns will have filters cleared.Column1, Column2...: The specific column(s) that must PRESERVE their active filters.
Store % of State = DIVIDE([Total Sales], CALCULATE([Total Sales], ALLEXCEPT(Dim_Store, Dim_Store[State])))REMOVEFILTERS Function
Definition: Modern DAX semantic filter modifier that specifically clears filter context without returning a table. Cleaner and faster than ALL when used inside CALCULATE.
Baseline Sales = CALCULATE([Total Sales], REMOVEFILTERS(Dim_Product[Brand]))
TableOrColumns: The table or list of columns from which active filters will be removed.
All Brands Sales = CALCULATE([Total Sales], REMOVEFILTERS(Dim_Product[Brand]))Common Mistakes & Limitations
- Using `ALL(Fact_Sales)` instead of `ALL(Dim_Store)`, which clears date, product, and customer filters inadvertently.
- Using `ALLEXCEPT` without realizing that adding new columns to the table can unintentionally clear them.
Keyboard Shortcuts
| Action | Windows | Mac |
|---|---|---|
| Format as Percentage | Measure Tools -> Click "%" | Measure Tools -> % |
| Quick Measure: % of Grand Total | Home -> Quick Measure -> % of Total | Quick Measure |
Pro Tips & Modern Alternatives
- Use `REMOVEFILTERS()` instead of `ALL()` when used as a filter argument in `CALCULATE` for improved code intent clarity.
- Use `ALLSELECTED()` if you want the denominator to respect slicers outside the visual matrix.