Context Transition: Invoking CALCULATE Inside Row Context
Overview & Learning Objectives
By default, any filter argument inside `CALCULATE()` ruthlessly overwrites any existing outer filter on that same column. While this is great when calculating benchmarks, it can be destructive when building targeted visual tables. `KEEPFILTERS()` changes this behavior: instead of overwriting outer filters, it intersects them (applying a logical AND), preserving existing visual selections.
- Understand the default overwrite behavior of `CALCULATE()`.
- Use `KEEPFILTERS()` to intersect filters rather than replace them.
- Eliminate visual bugs where measures repeat identical values across every row of a table.
Industry Standard
Standard: Modern DAX architectural standards at Microsoft recommend using `KEEPFILTERS()` whenever a filter condition should respect row context in matrix visuals without overwriting outer selections.
Real-World Example: Spice Delight Menu Pricing
Spice Delight displays a table of all menu items. We want a measure that only computes sales for "Burgers" without showing Burgers on the Pizza rows.
| Item Name | Category | Sales without KEEPFILTERS | Sales with KEEPFILTERS |
|---|---|---|---|
| Margherita Pizza | Pizza | ₹ 80,000 (Overwrites row to Burger sales!) | BLANK() (Preserves Pizza filter; intersection is empty) |
| Aloo Tikki Burger | Burger | ₹ 80,000 | ₹ 80,000 (Matches Burger) |
Syntax & Core Workflow
Burger Sales = CALCULATE([Total Sales], KEEPFILTERS(Dim_Product[Category] = "Burger"))
Parameters Breakdown
KEEPFILTERS(): A filter modifier used inside CALCULATE to force an intersection instead of an overwrite.Intersection Behavior: The engine evaluates: `(Current Row Filter) AND (KEEPFILTERS Condition)`.Blank Suppression: Rows that do not match the filter condition naturally evaluate to BLANK() and disappear from visuals.
Sample Walkthrough (Q&A)
Question: Why does a measure without KEEPFILTERS print the exact same number on every single row of a table visual?
Formula / Action: Standard CALCULATE overwrites the table's row header filter with its internal filter argument.
Result: Every row displays the exact same overwritten total.
Explanation: If a table is grouped by Category, standard `CALCULATE([Sales], Category="Burger")` replaces "Pizza", "Beverages", etc. with "Burger", printing Burger sales on every line. `KEEPFILTERS` prevents this overwrite.
Common Mistakes & Limitations
- Leaving out `KEEPFILTERS` and having report consumers complain that a specific KPI repeats identically across every row of a breakdown matrix.
- Using `KEEPFILTERS` when you explicitly wanted to overwrite an outer slicer (e.g. for an absolute benchmark).
Keyboard Shortcuts
| Action | Windows | Mac |
|---|---|---|
| Wrap in KEEPFILTERS | CALCULATE([Measure], KEEPFILTERS(...)) | KEEPFILTERS(...) |
| Duplicate Measure for Benchmark | Copy/paste formula in formula bar | Copy/paste |
Pro Tips & Modern Alternatives
- Use standard `CALCULATE([Sales], Col = "Value")` when you WANT to ignore outer slicers.
- Use `CALCULATE([Sales], KEEPFILTERS(Col = "Value"))` when you want the measure to harmonize with outer slicers.