Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
hemanth4pbi
Frequent Visitor

filter overwriting behavior of CALCULATE

I am not able to understand how nested CALCULATE statements overwrite the outer filter, in particular, one scenario where column overwrites the outer table filter:  Consider the following visual and measures. Model : Contoso from DAX book

hemanth4pbi_1-1672554508761.png 

1) Sales Amount = SUMX ( Sales, Sales[Quantity] * Sales[Net Price] )
2) Audio only Sales = CALCULATE ( [Sales Amount], 'Product'[Category] = "Audio" )

3) Nested CALC TABLE-FILTER FALSE =

CALCULATE (
    CALCULATE ( [Sales Amount], 'Product'[Category] = "Audio" ),
    FILTER ( ALL ( 'Product' ), FALSE () )
)
4) Nested CALC COLUMN-FILTER FALSE =
CALCULATE (
    CALCULATE ( [Sales Amount], 'Product'[Category] = "Audio" ),
    FILTER ( ALL ( 'Product'[Category] ), FALSE () )
)
I am unable to understand why the measure Nested CALC TABLE-FILTER FALSE is returning the blank while the measure Nested CALC COLUMN-FILTER FALSE is returning Audio sales.  I expect Nested CALC TABLE-FILTER FALSE should return Audio sales. Can you please help me to understand this behavior?
1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

First of all, presume that 'Product' table consists of other columns on top of 'Product'[Category], say 'Product'[ID].

 

Nested CALC TABLE-FILTER FALSE =
CALCULATE (
    CALCULATE ( [Sales Amount], 'Product'[Category] = "Audio" ),
    FILTER ( ALL ( 'Product' ), FALSE () )
)

Inner filter 'Product'[Category] = "Audio" overrides part of outer filter, ie 'Product'[Category] = BLANK(), but 'Product'[ID] = BLANK() DOES still exist, as well as any other filters on other columns of 'Product'.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

7 REPLIES 7
hemanth4pbi
Frequent Visitor

hemanth4pbi_0-1672562296136.png

@CNENFRNL  consider the query start at line 40, even though we set the filter context as empty, dax is returning product keys using ALL. PRODUCT[CATEGORY] = "Audio" is translated into

FILTER(ALL( PRODUCT[CATEGORY]),PRODUCT[CATEGORY] = "Audio").

@tamerj1 see the queries starting at line 25 and line 33, when we set the filter context to empty VALUES is returning empty list but ALL is still returning all values in that column.

 

 

What you want to say? Or you mean to teach me something new?


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Not at all. I am sorry if you feel like that. 

your point but 'Product'[ID] = BLANK() DOES still exist, as well as any other filters on other columns of 'Product'. You said Product[ID] = BLANK() still exist, I was trying to show you Product[ID] is not blank even thogh we set the filter on Product table is empty as you can see in the query at line 40.

(at line 40) You expect ALL() returns all the visible rows in the current filter context; but it's NOT the case for ALL(). It's now used as a top-level table expression, returning all the rows in a table, or all the values in a column, ignoring any filters that might have been applied.

 

Instead, you should use,

CALCULATETABLE (
    VALUES ( 'Product'[ProductKey] ),
    FILTER ( ALL ( 'Product' ), FALSE () )
)

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

CNENFRNL
Community Champion
Community Champion

First of all, presume that 'Product' table consists of other columns on top of 'Product'[Category], say 'Product'[ID].

 

Nested CALC TABLE-FILTER FALSE =
CALCULATE (
    CALCULATE ( [Sales Amount], 'Product'[Category] = "Audio" ),
    FILTER ( ALL ( 'Product' ), FALSE () )
)

Inner filter 'Product'[Category] = "Audio" overrides part of outer filter, ie 'Product'[Category] = BLANK(), but 'Product'[ID] = BLANK() DOES still exist, as well as any other filters on other columns of 'Product'.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Thanks for the help. CALCULATE is behaving as per your explanation.

tamerj1
Super User
Super User

Hi @hemanth4pbi 

because in (4) both the inner and outer CALCULATE filters are filtering the same column. Therefore, the inner CALCULATE replaces the outer CALCULATE filter and the result is "Audio". 

While number 3 filters all the products (another column with different granularity). This filter which is a empty table, is not replaced by the inner filter rather it is intersected with it and the interaction between the two filters is an empty table that returns blank. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors