<!-- https://learnsql.cpetoday.com/functions/dax/keepfilters -->
# KEEPFILTERS

Language: DAX
Category: Filter and context
Syntax: KEEPFILTERS(<filter>)
Summary: Combines a new filter with the existing filter, so only rows that satisfy both are kept.
Returns: Used inside CALCULATE, CALCULATETABLE or a table filter argument. It is not a value by itself.
Level: Advanced
Related: CALCULATE, CALCULATETABLE, REMOVEFILTERS, ALL, SUMMARIZECOLUMNS, VALUES

## 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
- **filter**: a Boolean filter on one column, such as `Channel[ChannelName] = "Online"`, or a table filter. Wrap it in `KEEPFILTERS`.

## 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.

```dax
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.

```dax
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
- Without `KEEPFILTERS`, a Boolean filter overrides the slicer. With it, the slicer still counts. Pick on purpose.
- An empty or blank result is often correct when the selection and the filter do not overlap. Explain it to readers.
- It also works with table filters.
- It is common inside `SUMMARIZECOLUMNS` filter arguments, so that a filter does not widen the rows the user is viewing.

## 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.
