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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

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
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.