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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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