Use of KEEPFILTERS Function

@Nick_M,

In this thread, I provided the following measure in response to a forum post question:

Hit Rate Filtered = 
    CALCULATE([Hit Rate Divide], 
        FILTER(Sales, Sales[Store Type] <> "SIS")
    )

In your reply, you indicated:

image

Can you please elaborate on that a bit? Still trying to wrap my head around exactly what KEEPFILTERS does and the benefit of using it here.

Thanks!

  • Brian

@BrianJ

So building on the example from the aforementioned thread. First thing we need to do is make a better data model. I created a few dimension tables and related as such:

Now we have a solid data model, we can start with the DAX. For this example I’ll stick with Total Sales Transactions. Always create the measures, no matter how easy it is.

Total Sales Transactions = SUM( 'Fact'[Sales Transactions] )
Measure%201

Keeping that in mind we can write the following measure for only sales that are not “SIS”

But what if we wanted to still to see the Full Price or Outlet total, and not the total of those two?

Here is the pbix file along with the data file if you want to see what I did to create the data model. There’s a parameter in PQ to change the file so be sure to change that

data.csv (671 Bytes)
Keep Filters.pbix (45.4 KB)

Enterprise%20DNA%20Expert%20-%20Small

1 Like

@Nick_M,

Thanks a lot for the detailed explanation.

OK, so KEEPFILTERS is keeping the implicit ALL associated with CALCULATE from overriding the current filter context, correct? Functionally, is it any different from this, or just a matter of being able to do the same thing many different ways in DAX?:

Sales without SIS Simple Filter = 
CALCULATE (
    [Total Sales Transactions],
    FILTER ( 'Fact', RELATED ( DimStoreType[Store Type] ) <> "SIS" )
)

Keep Filters vs Simple Filter.pbix (52.2 KB)

  • Brian

P.S. What program are you using for your annotated screenshots?

Pretty much. A good way to think of it is that instead of CALCULATE using Overwrite (which is the default way calculate works) it is using Intersect, or putting the filters in and AND.

There are always multiple ways to do things in DAX, like I showed earlier using Values and KeepFilters. So in this case, it really makes no difference. But, and there is always a but, there could be times where you would have to use Keepfilters, but I dont think that is something to really worry about.

If you want a good screenshot program, definitely get SnagIt. That’s what I have in my home office and it’s awesome. But at work I use freeware program called PickPick. Not bad for being free and so much better than the built in one in windows. But snagit is the best hands down.

Enterprise%20DNA%20Expert%20-%20Small

:+1: - got it. Thanks again for your help on both questions. Just downloaded SnagIt…