Ravindra BagaleCourses & study guides Track your progress

Guides

KEEPFILTERS in CALCULATE — Intersect Instead of Replace

KEEPFILTERS tells CALCULATE to intersect a new filter with filters that already exist on that column, instead of replacing them — the difference between “Online only, ignore City” and “Online inside the City I sliced”.

Friends! CALCULATE filter arguments look innocent until a slicer “disappears”. Why? Because many filters replace the filter on that column. How? We compare a plain boolean filter with KEEPFILTERS on a fictional FreshBasket Sales model (City + Channel). Slow and clear — this saves interview marks.

Quick answer

Vertical intent check:

  1. Ask: replace the column filter, or intersect with it?
  2. Plain: CALCULATE ( [Total Sales], Sales[Channel] = "Online" ) often replaces Channel filters.
  3. Intersect: wrap with KEEPFILTERS ( Sales[Channel] = "Online" ).
  4. Compare two cards while a City slicer is active.
  5. Name the measure so the intent is obvious later.
  6. Not every CALCULATE needs KEEPFILTERS — only when intersection is the rule.
CALCULATE ( [Total Sales], KEEPFILTERS ( Sales[Channel] = "Online" ) )

Why KEEPFILTERS, rows in / number out

Order ID City Amount Channel
A Mumbai 100 Online
B Mumbai 40 Store
C Nashik 80 Online
  1. City slicer = Mumbai. Rows in: A + B. Base [Total Sales] = 140.
  2. You want Online sales inside Mumbai.
  3. With a careful intersect mindset, keep City and add Channel = Online. Rows kept: only A. Number out: 100.
  4. If a replace-style Channel filter wiped a Channel slicer you cared about, the card can lie.
  5. KEEPFILTERS ( Sales[Channel] = "Online" ) is the “and also Online” tool when you need intersection with existing filters on that column.

Why you care:

  1. Managers say “Online for the cities on the slicer,” not “Online for the whole country while the City slicer lies.”
  2. Interviews ask replace vs intersect.
KEEPFILTERS vs replace Boolean filter in CALCULATE replaces column filter; KEEPFILTERS intersects. CALCULATEreplaces filter KEEPFILTERSintersects Both apply compare

Boolean filters inside CALCULATE often replace an existing column filter; wrap with KEEPFILTERS when you want to intersect instead.

What do I need before this guide?

Before and after (look at the tables first)

Before KEEPFILTERS Mumbai slicer; total 140.

Before

After KEEPFILTERS Online kept inside Mumbai; total 100.

After

The surprise: replace vs intersect

  1. You slice City = Mumbai.
  2. You write a CALCULATE that sets Channel = Online.
  3. Depending on how filters combine, you may no longer be “Online inside Mumbai” the way you imagined.
  4. Interviewers love asking whether you wanted replace or intersect.

Plain CALCULATE filter (replace mindset)

Online Sales Replace =
CALCULATE (
    [Total Sales],
    Sales[Channel] = "Online"
)
  1. Useful when you truly want Online sales regardless of other Channel filters.
  2. Dangerous when you thought City + Online would both stay the way you pictured.
  3. Test with City and Channel slicers before you trust the card.

KEEPFILTERS (intersect mindset)

KEEPFILTERS intersect Slicer City and KEEPFILTERS Platform both stay active. Slicer: City KEEPFILTERSPlatform=Online City ∩ Online intersect

Story: City slicer stays on; KEEPFILTERS ( Sales[Channel] = "Online" ) keeps only Online rows that still match the slicer.

Online Sales Kept =
CALCULATE (
    [Total Sales],
    KEEPFILTERS ( Sales[Channel] = "Online" )
)

Vertical reading:

  1. Start from current filter context (City slicer, visuals, …).
  2. KEEPFILTERS adds Channel = Online without wiping existing filters the way a naked replace would.
  3. Result = rows that satisfy both stories — Mumbai Online 100 on the sample.
KEEPFILTERS in CALCULATE Wrap the filter argument with KEEPFILTERS inside CALCULATE. CALCULATEexpression KEEPFILTERS ( column = value )filter argument wrap

Pattern: CALCULATE ( [Total Sales], KEEPFILTERS ( Sales[Channel] = "Online" ) ) — filter argument wrapped on purpose.

FreshBasket story (fictional)

FreshBasket ops want “Online sales for the cities on the slicer”, not “Online for the whole country while the City slicer lies to us”. That sentence is KEEPFILTERS.

Mistakes and calm fixes

Symptom Likely cause Fix
Slicer ignored Filter replaced Wrap with KEEPFILTERS
Still wrong City Wrong column / model Check Channel and City columns
Same as base measure Condition always true Verify sample data
Overused KEEPFILTERS Copy-paste habit Use only when intersection is required

Ghabru naka 😅 — one side-by-side card test beats ten forum threads.

Ravindra Bagale's Tip

Interview trap: “Does CALCULATE add or replace filters?” Calm answer: “Filter arguments typically replace filters on that column; I use KEEPFILTERS when I need to intersect with the existing filter context.” Got it?

Practice task

  1. Build Online Sales Replace and Online Sales Kept.
  2. Slice City = Mumbai, Channel = all (expect Online-in-Mumbai 100 with kept intent).
  3. Write which measure kept City.
  4. Flip Channel slicer; note differences.
  5. Rename measures so replace vs kept is obvious.

Learn it properly

Course lessons:

Related guides: FILTER inside CALCULATE · Context transition

Got it? CALCULATE filters often replace; KEEPFILTERS intersects. Test with a City slicer before you swear the measure is right. Next: IF and SWITCH. Let's continue.

Frequently asked questions

What does KEEPFILTERS do?

It tells CALCULATE to intersect the new filter with existing filters on that column, instead of replacing them.

When do I need it?

When a CALCULATE filter argument would wipe a slicer/visual filter you still want on the same column (or related filter), and you need both to apply.

Is KEEPFILTERS only for booleans?

You wrap filter arguments (including more advanced ones) — beginners usually meet it on simple column filters first.

Does every CALCULATE need KEEPFILTERS?

No. Many measures should replace filters on purpose. Use it when intersection is the business rule.

Related to FILTER?

Different jobs: FILTER builds a table; KEEPFILTERS changes how a filter argument combines with existing context.

Course lesson?

CALCULATE — the most important function, in the DAX chapter.