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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
han_rj
Helper IV
Helper IV

Understand Nested Calculate dax Code

Hi All, 

 

I am exploring nested calculate dax, out of this dax I was expecting only Audio Sales to be displayed but the filter context on Product Category is retained in Measure Calculates measures. Please may I have help understand what I am missing.

han_rj_1-1737451011459.png

 

DataModel:

han_rj_0-1737452875365.png

 

 

3 ACCEPTED SOLUTIONS
bhanu_gautam
Super User
Super User

@han_rj The issue with your DAX formula is that the nested CALCULATE function does not work as expected because the inner CALCULATE does not return a scalar value that can be used in the outer CALCULATE

Try this

Measures =
VAR calc = CALCULATE([Sales Amount], 'Product Category'[Category] = "Audio")
RETURN calc




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

sanalytics
Super User
Super User

@han_rj 
why you are using variable? variable scope is limited..
Just use CALCULATE([Sales Amount], 'Product Category'[Category] = "Audio")
Or 
CALCULATE([Sales Amount],FILTER(ALL( 'Product Category'[Category] ),'Product Category'[Category] = "Audio") )
This is not the case of nested calculate.

 

Regards

sanalytics

View solution in original post

johnt75
Super User
Super User

Variables in DAX are not really variable, they are constants. They are only ever evaluated once, and then they do not change. So your calc variable is evaluated in the original filter context, and the subsequent CALCULATE has no effect on that.

View solution in original post

3 REPLIES 3
johnt75
Super User
Super User

Variables in DAX are not really variable, they are constants. They are only ever evaluated once, and then they do not change. So your calc variable is evaluated in the original filter context, and the subsequent CALCULATE has no effect on that.

sanalytics
Super User
Super User

@han_rj 
why you are using variable? variable scope is limited..
Just use CALCULATE([Sales Amount], 'Product Category'[Category] = "Audio")
Or 
CALCULATE([Sales Amount],FILTER(ALL( 'Product Category'[Category] ),'Product Category'[Category] = "Audio") )
This is not the case of nested calculate.

 

Regards

sanalytics

bhanu_gautam
Super User
Super User

@han_rj The issue with your DAX formula is that the nested CALCULATE function does not work as expected because the inner CALCULATE does not return a scalar value that can be used in the outer CALCULATE

Try this

Measures =
VAR calc = CALCULATE([Sales Amount], 'Product Category'[Category] = "Audio")
RETURN calc




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

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.