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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
ilcaa722
Frequent Visitor

please explain why MAX(biorthYear) works but measure version doesnt

hello, learning DAX and need to understand WHY one works but not other...

i have a [BirthDate] column and I created a calculated Column [BirthYEAR].  I did this to filter my [total customers] born before [BirthYEAR] so user can select a birthYear and it will show a total customers born before this year.  

this code works with slicer based on [BirthYear] column (birthYear is not in pivot table)

 

total customers born before :=
CALCULATE([total customers],
FILTER( ALL(Customers),
   Customers[birthYear] <= max(Customers[birthYear]) ))

 

BUT this code does NOT,

create sperate measure & use in another measure as a value. year_slicer:= MAX([BirthYEAR])

total customers born before :=
CALCULATE([total customers],
  FILTER( ALL(Customers),
      Customers[birthYear] <= [year_slicer] ))

the code that use a [measure] returns the total customers in Table

BUT, if i use a seperate disconnected table as the years and use the 2nd method i posted it work!

 

i can figure out the logic. a quick explanation would be helpful

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @ilcaa722 

The reason is context transition, a very important concept in DAX.

On your first version  max(Customers[birthYear]) always returns the desired value (that selected in the slicer)

On your second however, context transition kicks in (it always does when there is a calculate or when a measure is used). The result yielded by the measure is the  value for Customers[birthYear] in the row currently under evaluation in FILTER. Therefore the Customers[birthYear] always equals  [year_slicer]  and the condition

Customers[birthYear] <= [year_slicer]

is always true.

Check this out:

https://www.sqlbi.com/articles/understanding-context-transition/

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

When you call a measure, there is an implicit CALCULATE involved that performs a context transition. Your second code box is equivalent to:

total customers born before :=
CALCULATE (
    [total customers],
    FILTER (
        ALL ( Customers ),
        Customers[birthYear] <= CALCULATE ( MAX ( Customers[birthYear] ) )
    )
)

 

I recommend reading the following article for more detail. It discusses an example very similar to yours.

https://www.sqlbi.com/articles/understanding-context-transition-in-dax/

AlB
Community Champion
Community Champion

Hi @ilcaa722 

The reason is context transition, a very important concept in DAX.

On your first version  max(Customers[birthYear]) always returns the desired value (that selected in the slicer)

On your second however, context transition kicks in (it always does when there is a calculate or when a measure is used). The result yielded by the measure is the  value for Customers[birthYear] in the row currently under evaluation in FILTER. Therefore the Customers[birthYear] always equals  [year_slicer]  and the condition

Customers[birthYear] <= [year_slicer]

is always true.

Check this out:

https://www.sqlbi.com/articles/understanding-context-transition/

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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