Study FAQ
How do I preserve or replace report filters in a DAX measure?
Also asked as 2
- When should I use KEEPFILTERS or REMOVEFILTERS with CALCULATE?
- How can I change one DAX filter without removing unrelated report context?
Answer
Use CALCULATE to evaluate a measure in a modified filter context. A normal filter argument replaces existing filters on the same columns; KEEPFILTERS intersects the new condition with existing filters. REMOVEFILTERS clears the specific filters you name.
For example, assuming [Revenue] and Product[Color] exist:
Selected Red Revenue =
CALCULATE ( [Revenue], KEEPFILTERS ( Product[Color] = "Red" ) )
A selection that excludes red yields no qualifying red rows rather than being overwritten. For a share-of-all-colors denominator, use CALCULATE ( [Revenue], REMOVEFILTERS ( Product[Color] ) ) so date and customer context can remain.
Prefer a Boolean column filter when it fully expresses the condition. FILTER is appropriate when you must evaluate a measure or a more complex row-dependent condition over a table; scope that table as narrowly as the rule permits. Boolean CALCULATE filters have restrictions, including not directly referencing measures or columns from multiple tables.
Test a matching selection, a conflicting selection, multiple selections, and totals. Removing all filters from a whole table can discard more context than intended, so verify exactly what the denominator or comparison must ignore.
Full explanation
DP-600: Advanced DAX Patterns for Enterprise Semantic Models
Study guide · DP-600
Read the full explanation