KEEPFILTERS
Choose whether to honor the selection
A fixed category measure and a measure constrained by a user selection are different metrics. KEEPFILTERS requests overlap with filters already targeting the same column. REMOVEFILTERS clears the specified restrictions. Use the clean Import model from Chapter 20. FactSales has five lines, RevenueUSD and Quantity; DimProduct contains ProductKey, Product and Category; DimRegion contains Region. Active one-to-many relationships filter the fact from each dimension. Use dimension columns for selections, no RLS, no other report filters, and fixed USD. Reuse the existing [Context Revenue] measure (SUM(FactSales[RevenueUSD])). Every formula below is a separate measure unless identified as a query or column. Expected results are fixture-derived; native DAX execution is NOT RUN.
Example 1 — Intersection instead of replacement
Home Within Selection =CALCULATE([Context Revenue], KEEPFILTERS(DimProduct[Category] = "Home"))North + Stationery yields no rows and BLANK; North + Home gives 30. With North and both Home and Stationery selected, only Home contributes (30). Compare Home Revenue from lesson 1, which returns 30 even if Stationery alone is selected. Without any category restriction both measures yield Home revenue in the current region. A recorded zero is different from a missing set of fact rows.
Example 2 — Define category revenue share
Revenue Across Categories =CALCULATE([Context Revenue], REMOVEFILTERS(DimProduct[Category]))Category Share = DIVIDE([Context Revenue], [Revenue Across Categories])Use Category as matrix rows and Region = North; do not select any other product fields. Expected:
| Category | Revenue USD | Denominator USD | Share |
|---|---|---|---|
| Stationery | 24 | 104 | 23.08% |
| Home | 30 | 104 | 28.85% |
| Travel | 50 | 104 | 48.08% |
| Total | 104 | 104 | 100% |
Rounded percentages may not sum exactly to 100%. The denominator retains the region restriction. Removing Category also removes a category slicer restriction; this is not share of selected categories only. With an independent Product restriction the denominator can still be restricted. Removing all of DimProduct would express a broader question; removing all report filters is broader still. DIVIDE protects an empty or zero denominator.
Avoid overpromising filter removal
ALL(DimProduct[Category]) can also be used as a filter modifier in this simple model; ALL with a table or column argument can additionally supply a table expression. REMOVEFILTERS cannot supply a table. Multiple filters on the same table can interact through auto-exist (the engine can merge existing combinations), so do not assume every discarded combination can be recovered. Neither function is an authorization override. These examples use a single category filter and a separate region dimension.
Practice — check the denominator
Under South, calculate the Stationery and Home shares and the grand total. Explain why a category slicer selecting Home alone does not turn the Home share into 100%. State what should happen for Travel in South.