Power BI Advanced AnalyticsLesson 27 of 53
Lesson 27 of 53

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 NameOutlet Sales (₹)Chain Grand Total (₹)% of Chain Total
Indiranagar Outlet1,50,0005,000,00030.0%
Koramangala Outlet2,00,0005,000,00040.0%
Whitefield Outlet1,50,0005,000,00030.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:

Function 1

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.

Syntax:
Grand Total Sales = CALCULATE([Total Sales], ALL(Fact_Sales))
Parameters Breakdown:
  • TableOrColumn: The entire table (e.g. `ALL(Dim_Product)`) or specific columns (e.g. `ALL(Dim_Product[Category])`) to clear filters from.
Real-World Example (Calculating % Share of All Products):
Problem / Scenario: How do you calculate each product category's % contribution to grand total sales?
Formula: Category % Share = DIVIDE([Total Sales], CALCULATE([Total Sales], ALL(Dim_Product[Category])))
Result: 34.2%
Why it works: ALL(Dim_Product[Category]) strips the visual's row header filter, producing the stable grand total denominator.
Function 2

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.

Syntax:
Regional Sales Baseline = CALCULATE([Total Sales], ALLEXCEPT(Dim_Store, Dim_Store[Region]))
Parameters Breakdown:
  • Table: The base table whose columns will have filters cleared.
  • Column1, Column2...: The specific column(s) that must PRESERVE their active filters.
Real-World Example (Share within State / Region):
Problem / Scenario: How do you calculate a store's sales share within its own State, regardless of city or tier slicers?
Formula: Store % of State = DIVIDE([Total Sales], CALCULATE([Total Sales], ALLEXCEPT(Dim_Store, Dim_Store[State])))
Result: 18.5%
Why it works: ALLEXCEPT clears city and store filters while strictly locking the active State filter.
Function 3

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.

Syntax:
Baseline Sales = CALCULATE([Total Sales], REMOVEFILTERS(Dim_Product[Brand]))
Parameters Breakdown:
  • TableOrColumns: The table or list of columns from which active filters will be removed.
Real-World Example (Clean Denominator Benchmarking):
Problem / Scenario: What is the modern best practice for removing brand filters in DAX without generating an in-memory virtual table?
Formula: All Brands Sales = CALCULATE([Total Sales], REMOVEFILTERS(Dim_Product[Brand]))
Result: ₹ 1,20,00,000
Why it works: REMOVEFILTERS expresses clear analytical intent: it behaves purely as a filter argument to CALCULATE, saving memory.

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

ActionWindowsMac
Format as PercentageMeasure Tools -> Click "%"Measure Tools -> %
Quick Measure: % of Grand TotalHome -> Quick Measure -> % of TotalQuick 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.