Downloads
DAXFilter and contextAdvanced

KEEPFILTERS

Combines a new filter with the existing filter, so only rows that satisfy both are kept.

Syntax
KEEPFILTERS(<filter>)

Returns: Used inside CALCULATE, CALCULATETABLE or a table filter argument. It is not a value by itself.

What it does

A normal CALCULATE filter replaces whatever filter already applies to that column. KEEPFILTERS changes that: the new filter is combined with the existing one, and only rows that satisfy both are kept. If a user has selected Store on a channel slicer, and your measure asks for Online, the result is the intersection, which is empty. Use it when the business rule must respect what the user chose.

Syntax and arguments

Example

A category measure should count only electronics, but it must respect the user's category slicer. If the user picks Audio, the result should be empty, not electronics.

Electronics Sales (Respecting Slicer) =
CALCULATE (
    [Total Sales],
    KEEPFILTERS ( Product[ProductCategory] = "Electronics" )
)

With no slicer, the result is electronics sales. With Audio selected, the two filters have nothing in common, so the result is blank. That blank is correct, and a note on the report should say so.

Example: a second use

The contrast with a plain filter shows why the choice matters.

Online Sales (Replaces Slicer) =
CALCULATE (
    [Total Sales],
    Channel[ChannelName] = "Online"
)

Online Sales (Within Selection) =
CALCULATE (
    [Total Sales],
    KEEPFILTERS ( Channel[ChannelName] = "Online" )
)

When the user selects Store, the first measure still shows online sales, because its filter replaces the slicer. The second shows blank, because it only counts online rows inside the Store selection.

Things to watch

In business terms

Segment reports that must respect the page, such as a government segment inside a region slicer, or a budget line that counts only the cost centers the user selected. It stops a measure from silently ignoring what the user chose.

Related functions

All DAX functions · View as Markdown · DAX fundamentals