DAX Filter - KEEPFILTERS function



Description

Modifies how filters are applied while evaluating a CALCULATE or CALCULATETABLE function.

Syntax

KEEPFILTERS (<expression>) 

Parameters

Sr.No. Term & Definition
1

Expression

Any DAX expression.

Return Value

DAX KEEPFILTERS function does not return any value.

Remarks

You can use DAX KEEPFILTERS function within the context CALCULATE and CALCULATETABLE functions, to override the standard behavior of those functions.

When you use KEEPFILTERS, any existing filters in the current context are compared with the columns in the filter arguments, and the intersection of those arguments is used as the context for evaluating the expression.

The net effect over any one column is that both sets of arguments apply −

  • The filter arguments used in CALCULATE function.
  • The filters in the arguments of the KEEPFILTER function.

In other words, while CALCULATE filters replace the current context, KEEPFILTERS adds filters to the current context.

Example

= SUMX ( 
   CALCULATETABLE (East_Sales, 
   FILTER(East_Sales,East_Sales[Product] = [Product]), 
   KEEPFILTERS(East_Sales[Product]<>"Soap")), 
   East_Sales[Sales Amount]
) 
dax_functions_filter.htm
Advertisements