Power BI

How to Use KEEPFILTERS() and REMOVEFILTERS() in Power BI

How to Use KEEPFILTERS() and REMOVEFILTERS() in Power BI

Table of Contents

Introduction

If you’ve spent time writing DAX, you’ve probably run into a scenario where a measure returns a number that doesn’t make sense, until you realize filter context is the culprit. Two functions that give you precise control over filter context are KEEPFILTERS() and REMOVEFILTERS(). They sit at opposite ends of the same problem: one preserves existing filters; the other wipes them out. Understanding both will make your DAX measures more predictable.

Learn more about DAX: Learn How to Write DAX Queries in DAX Studio Using Query Builder

Filter Context

It is important to remember that every DAX measure is evaluated inside a filter context. The filter context is a set of filters currently applied by slicers, rows/columns in a visual, or other DAX functions like CALCULATE(). Functions like KEEPFILTERS() and REMOVEFILTERS() exist specifically to modify how that filter context behaves.

KEEPFILTERS()

KEEPFILTERS() is a DAX function in Power BI that controls the behavior of filter within CALCULATE().

KEEPFILTERS
Syntax for KEEPFILTERS()

Note: If you call KEEPFILTERS() with no arguments, it removes all filters from the entire model.

For information about KEEPFILTERS(): DAX KEEPFILTERS(): Improve Accuracy in Power BI Measures

Example of KEEPFILTERS()

For seeing KEEPFILTERS() in action refer to the exercise file provided at the end of this blog. For this exercise, we have setup a Matrix visual showing Total Sales Amount and Sales in Australia as below:

Total Sales and Sales in Australia for analysis
Total Sales and Sales in Australia for analysis

The same value is shown for all the countries  in sales in Australia column and this value basically is the sales amount for Australia only. For all countries other than Australia, the initial filter context conflicts with that from CALCULATE() and CALCULATE() overrides the incoming filter context. 

With introduction of KEEPFILTERS() DAX function we can overcome this:

  1. Right click on All Measures in the Fields, click on new measure.

     Measure tools open. 

2. Type the following formula in the formula bar and press Enter.

Sales in Australia using KEEPFILTERS (CM) = 
CALCULATE ( 
    [Total Sales Amount (CM)], 
    KEEPFILTERS ( SalesTerritory = ”Australia” ) 
)

In the above expression: 

  •  KEEPFILTER() modifies and filters the Sales from “Australia” only and stores results in a virtual table.

  •  The total sales amount for the rows in the virtual table is calculated.

3. In the Matrix visual add the newly created measure Sales in Australia using KEEPFILTERS().

Sales in Australia using KEEPFILTERS() for analysis
Sales in Australia using KEEPFILTERS() for analysis

Notice the change in behaviour of CALCULATE(). Sales in Australia using KEEPFILTERS() shows values only for cells where the incoming filter context is not in conflict with that of CALCULATE(). 

Common use cases

  • Preventing a CALCULATE() filter from silently overriding row/column context in a visual.
  • Building measures that should only return values when the existing context “agrees” with the filter you’re adding.
  • Avoiding subtle bugs where totals look right, but row-level breakdowns are wrong.

REMOVEFILTERS()

REMOVEFILTERS() can only be used to clear filters but not to return a table. This is essentially a more modern, readable alternative to ALL() when used inside CALCULATE(). In fact, REMOVEFILTERS() was introduced as a synonym for ALL() in this context, but the name makes the intent much clearer to anyone reading your formula later.

Syntax for REMOVEFILTERS()
Syntax for REMOVEFILTERS()

Example of REMOVEFILTERS()

Referring to the same exercise file, let’s create a new measure.

4. Right click on All Measures in the Fields, click on new measure.

   Measure tools open.

5. Type the following formula in the formula bar and press Enter.

Sales using REMOVEFILTERS (CM) =
CALCULATE ( [Total Sales Amount (CM)], REMOVEFILTERS ( Sales Territory ) )

6. In the Matrix visual add the newly created measure Sales using REMOVEFILTERS().

Sales in Australia using KEEPFILTERS() for analysis

Notice the change in behaviour of CALCULATE(). Sales using REMOVEFILTERS() shows the total sales amount bypassing all the filters.

Common use cases

  • Calculating a grand total that ignores slicers (e.g., “% of total” measures).
  • Building “all-time” or “all-products” comparisons against filtered values.
  • Resetting filters before applying a new, more specific filter.

KEEPFILTERS() vs. REMOVEFILTERS(): Side by Side

 

KEEPFILTERS()

REMOVEFILTERS()

What it does

Combines new filter with existing filter context.

Clears existing filters.

Typical placement

Inside a filter argument of CALCULATE().

As a filter argument of CALCULATE().

Effect on context

Narrows (intersects).

Widens (resets).

Good for

Respecting row/visual context while adding a condition.

Ignoring row/visual context entirely.

Key Takeaways

  • Use REMOVEFILTERS()when you want a calculation to ignore filters on specific columns or tables entirely. It is great for grand totals and “all” comparisons.
  • Use KEEPFILTERS()when you want a filter inside CALCULATE() to combine with, rather than override, the existing filter context. It is essential for getting correct row-level results in matrices and tables.
  • Getting these two functions right is often the difference between a report that “looks fine” and one that’s actually accurate at every level of detail.

Conclusion

KEEPFILTERS() and REMOVEFILTERS() may look like small, optional additions to your DAX toolkit, but they directly control whether your measures are correct or just plausible looking.

REMOVEFILTERS() lets you step back and calculate against a wider or total context, while KEEPFILTERS() lets you layer in new conditions without accidentally erasing the filters already set by your report’s visuals.

FAQs

Use it whenever you want a CALCULATE() function to narrow down the existing context instead of replacing it. Most commonly inside matrices or tables where row/column context should still apply alongside your explicit filter condition.

Yes. Calling REMOVEFILTERS() with no arguments clears all filters from the entire model, similar to ALL() with no arguments. It is useful for true grand-total calculations.

Further Learning and Resources 

To learn more about Power BI, check out our courses here:  

Want to learn how Microsoft 365 Copilot transforms everyday work with AI? Check out our Course:   

  For end-to-end custom solution for your reports, check out our sister website:

Want to learn more about Power BI and how to make reports more efficiently?  

Power BI training in Australia: We offer comprehensive training sessions across various cities, including :  

Ready to enhance your Power BI skills? Sign up for our training courses and explore our wide range of resources designed to elevate your data analytics capabilities.   

Want end-to-end solutions for your Power BI Reports? Get in touch with our consultants at Power BI Consulting & Training Services in Australia 

Contact Us: Make an enquiry about our Power BI courses and find the proper training for you.   

 

One thought on “How to Use KEEPFILTERS() and REMOVEFILTERS() in Power BI”

  1. Sameen Fatima says:

    I’m confused about `KEEPFILTERS()` and `REMOVEFILTERS()` in Power BI. What do these functions actually do, and when would I use one instead of the other?

Leave a Reply

Your email address will not be published. Required fields are marked *