DAX Filter - KEEPFILTERS function


Advertisements

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

Useful Video Courses


Video

Mastering DAX and Data Models in Power BI Desktop

53 Lectures 5.5 hours

Abhay Gadiya

Video

Mastering DAX Studio

Featured

24 Lectures 2 hours

Randy Minder

Video

DAX / Power BI - Customer and Sales Analysis Deep Dive

26 Lectures 4.5 hours

Randy Minder

Advertisements