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
SuraMan
Advocate II
Advocate II

Evaluation context inside FILTER

Hello,

 

I have a question about how evaluation takes place in the code snippet below. This filter() returns all the dates in 'Date'[Date] which are equal or less than the highest date in the current filter context.

 

FILTER ( 
ALL ( ‘Date’[Date] ),
‘Date’[Date] <= MAX( ‘Date’[Date] )
)

 

My question is, since ALL() removes any filters on 'Date'[Date] above, why does MAX(‘Date’[Date])  not return the last date in the full table 'Date'[Date], ignoring the current filter context?

For the above code to work as intended, MAX( ‘Date’[Date] ) has to be evaluated in the original filter context disregarding the effects of ALL(), however, it is not clear to me what rules determine that MAX() has to be evaluated in that manner.

If we look at the third line; it looks like ‘Date’[Date] evaluates in ALL() context while MAX(‘Date’[Date]) evaluates in the original context. Two different evaluation contexts for the two references of ‘Date’[Date] in the same line!

If you can clarify this, that would be wonderful.

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@SuraMan 

 

I believe the rule to remember is that
Inside a MEASURE

1) Expressions like SUM,MAX will always respond to available FILTER CONTEXT
Since FILTER is only an iterator and introduces ROW CONTEXT only,    MAX( ‘Date’[Date] ) responds to the FILTER context of the VISUAL (Matrix, Table, chart etc) which you are using.
If you use CALCULATE(MAX( ‘Date’[Date] )), we should get different results because in that case it will transform the ROW CONTEXT introduced by FILTER function into FILTER CONTEXT.
2) Naked column references (TableName[ColumnName]) inside an INTERATOR like FILTER,SUMX,MAXX will refer to ROW CONTEXT of that ITERATOR

 


Regards
Zubair

Please try my custom visuals

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

@SuraMan 

 

I believe the rule to remember is that
Inside a MEASURE

1) Expressions like SUM,MAX will always respond to available FILTER CONTEXT
Since FILTER is only an iterator and introduces ROW CONTEXT only,    MAX( ‘Date’[Date] ) responds to the FILTER context of the VISUAL (Matrix, Table, chart etc) which you are using.
If you use CALCULATE(MAX( ‘Date’[Date] )), we should get different results because in that case it will transform the ROW CONTEXT introduced by FILTER function into FILTER CONTEXT.
2) Naked column references (TableName[ColumnName]) inside an INTERATOR like FILTER,SUMX,MAXX will refer to ROW CONTEXT of that ITERATOR

 


Regards
Zubair

Please try my custom visuals

Thanks @Zubair_Muhammad  for the explanation

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