Ravindra BagaleCourses & study guides मराठी Track your progress

13. DAX: Data Analysis Expressions

13.21 KEEPFILTERS in Power BI: How a Slicer Hits a Measure, with Example

KEEPFILTERS in Power BI with example — in 30 seconds

What: KEEPFILTERS makes a CALCULATE filter join the slicer (AND) instead of replacing it.

Why: Sometimes "Blinkit sales" must mean "Blinkit, but only inside what the user picked".

Tiny example: Platform slicer = Amazon Now. Replace version shows ₹800. KEEPFILTERS version shows blank.

First look at the data (before → after):

KEEPFILTERS in Power BI with example: before and after tables, fictional Blinkit Maharashtra data

Same before / after tables as text

Before — Orders · Platform slicer = Amazon Now

Order ID City Platform Amount (₹)
101 Pune Blinkit 500
102 Nashik Blinkit 300
103 Pune Amazon Now 700

Formula / click path

Blinkit Sales      = CALCULATE([Total Sales], Orders[Platform] = "Blinkit")
Blinkit Sales Keep = CALCULATE([Total Sales], KEEPFILTERS(Orders[Platform] = "Blinkit"))

After — Cards with Platform slicer = Amazon Now

Measure Value
Total Sales ₹700
Blinkit Sales (replace) ₹800
Blinkit Sales Keep (blank)

Do it step by step:

  1. Create both measures.
  2. Add a Platform slicer. Select Amazon Now.
  3. Check the three cards against the table.
  4. Pick the version your manager means. Write it in the measure description.

Slicer mhanje filter context. CALCULATE madhla simple equality tyach column var junna filter replace karto. KEEPFILTERS to replace nahi honar.

Section 13.8 states the replace rule. Here is the pattern students need when the slicer and the measure must both apply (an intersection).

Blinkit Sales (keep slicer) =
CALCULATE(
    [Total Sales],
    KEEPFILTERS(Orders[Platform] = "Blinkit")
)

Without KEEPFILTERS, Orders[Platform] = "Blinkit" removes the slicer's platform filter and forces Blinkit. With KEEPFILTERS, a slicer set to Amazon Now and this measure produce blank: the intersection is empty. A slicer set to Blinkit, or a slicer that still includes Blinkit, keeps Blinkit rows.

A slicer on another column (city, category) is already an AND. It is not replaced by a platform filter. City = Pune and the measure forces platform Blinkit: you get Blinkit in Pune. That part confuses people. Replacement happens on the same column the measure filters.

CALCULATETABLE is the same engine as CALCULATE, but it returns a table, not a single value. Use it when the next function wants a table (COUNTROWS, INTERSECT, a calculated table).

Pune Orders Table =
CALCULATETABLE(
    Orders,
    DarkStore[City] = "Pune"
)

You would not drop that table into a card. You would count it or use it inside another expression. KEEPFILTERS works as a filter argument there too.

Worked example. The slicer is Platform = Amazon Now, city slicer = Nashik. [Blinkit Sales] from section 13.8 still shows Blinkit Nashik sales, because the platform filter was replaced. [Blinkit Sales (keep slicer)] shows blank, because Amazon Now and Blinkit do not overlap. Students who wanted "Blinkit, but only if the user has not chosen something else" need KEEPFILTERS. Students who wanted "always Blinkit, ignore the platform slicer" should not add it.

Ravindra Bagale's Tip

A common mistake is wrapping every CALCULATE filter in KEEPFILTERS out of habit. Then the "Blinkit" card goes blank as soon as someone clicks Amazon Now, and they think the measure is broken. Use KEEPFILTERS only when the slicer must survive. Other filters will replace the slicer; use that on purpose.

Loading DAX practice tasks...

  1. Pune sales on every row (Easy): Shown per Store City. Measure: Pune Sales = [Total Sales] with a filter City = "Pune".
  2. Pune sales only on the Pune row (Easy): Shown per Store City. Measure: Pune Kept = [Total Sales] for Pune, keeping the row filter.
  3. Zepto only on its row (Easy): Shown per Platform. Measure: Zepto Kept = [Total Sales] for Zepto, keeping the row filter.
  4. Dairy units everywhere (Medium): Shown per Category. Measure: Dairy Qty = [Total Qty] with Category = "Dairy".
  5. Dairy units only on Dairy (Medium): Shown per Category. Measure: Dairy Kept = [Total Qty] for Dairy, keeping the row filter.
  6. Slicer gets overwritten (Medium): Slicer: Store City = Nashik. Measure: Pune Sales = [Total Sales] with City = "Pune".
  7. Slicer and filter together (Medium): Slicer: Store City = Pune and Mumbai. Measure: Pune Kept = [Total Sales] for Pune, keeping the slicer.
  8. Big lines per city (Hard): Shown per Store City. Measure: Big Line Sales = [Total Sales] where Qty is 3 or more, using KEEPFILTERS.
  9. Share of Pune (Hard): Shown per Store City. Measure: Vs Pune = [Total Sales] ÷ Pune sales. Use DIVIDE.
  10. Zepto lines in Mumbai slicer (Hard): Slicer: Store City = Mumbai. Measure: Zepto Lines = row count of Orders for Zepto, keeping filters.

Ravi Sir's Cards for this lesson

मराठी cards