Knowledge Base
Open App
KB 100503

Filtered table as filter argument (multiple columns predicate with AND condition)


A FILTER function filtering entire table using an AND condition on multiple columns is used as a filter argument in functions such as CALCULATE, CALCULATETABLE, etc.

Remarks

Because the conditions are applied with an && operator, the multiple columns predicate can be transformed into one filter argument for each column, without filtering an entire table.

In order to keep the same semantics as the original filter, apply KEEPFILTERS over each filter argument.

Recommended articles:

Example

Remove the Customer iterator and use KEEPFILTERS around each condition to maintain the same semantics, so the filter is applied only to the Customer[Country] and Customer[Age] columns instead of filtering the entire Customer table.

Original code

CALCULATE (
    [Sales Amount],
    FILTER ( 
        Customer,
        Customer[Country] = "Canada" 
            && Customer[Age] >= 21
    )
)

Possible optimization

CALCULATE (
    [Sales Amount],
    KEEPFILTERS ( Customer[Country] = "Canada" ),
    KEEPFILTERS ( Customer[Age] >= 21 )
)