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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
akapelle
Frequent Visitor

Sumx measure result differs when replacing an expression with an identical variable

When I enter part of a sumx expression as variable instead of directly coding it in the measure, I get a different (the expected) result.

 

Below a simplified example. Sample data =

MonthAccountIDBalanceTotal
11001500
11002500
21001500
21002500

 

Expected result of measure

Multiply the balance of each row with the max selected month. So when both months selected, multiply each 500 with 2.
Note: I know in this simplified example I don't need sumx but can simply do sum(Balance)*calculate(max(allselected,Month)). But in the more complex real life example I do need a sumx measure and the difference is same as below.

 

I originally created this measure 'Balance x maxmonth':

 

 

var _sumx = 
    sumx(Balances,Balances[Balance]*
        calculate(
            max(Balances[Month])
            ,ALLSELECTED(Balances[Month])
            )
        )
return
_sumx

 

 

This does not return the expected result when a visual is aggregated on month level. However if I replace the 'calculate' part of the sumx expression into a variable like below it does:

 

Balance x maxmonth with var = 
var _maxmonth = 
    calculate(
        max(Balances[Month])
        ,ALLSELECTED(Balances[Month])
        )
var _sumx = 
    sumx(Balances,Balances[Balance]*
    _maxmonth
    )
return
_sumx

 

Results with and without variable for the calculate part of the expression:

akapelle_0-1634641350850.png


Can anyone explain why the use of a var could lead to a different result outcome? 
I'm happy with the fix but want to understand this difference in behavour when using variables within a sumx expression.

 

Many thanks.

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@akapelle In the first case, the CALCULATE is being evaluated for each row while in the second case it is evalulated once within the full context of the measure.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Community Champion
Community Champion

@akapelle In the first case, the CALCULATE is being evaluated for each row while in the second case it is evalulated once within the full context of the measure.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.

Top Solution Authors