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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Traciicolliins
New Member

How to SUM a measure that has variables

Why does this not show the proper total?
 
Gained ACS KPI =
VAR _thisyear = [yDrink ACS Dynamic TY]
VAR _lastyear = [yDrink ACS Dynamic LY]
return
if(and(_thisyear>0,_lastyear=0),1,0)
 
when i put this in a table, the flag works (correctly flagging accounts that are gained (ACS TY=1, ACS LY=0) but the sum doesn't work
Traciicolliins_0-1726163047925.png

 

 
2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@Traciicolliins First, please vote for this idea: https://ideas.powerbi.com/ideas/idea/?ideaid=082203f1-594f-4ba7-ac87-bb91096c742e

This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

Also: https://youtu.be/uXRriTN0cfY
And: https://youtu.be/n4TYhF2ARe8



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

v-zhouwen-msft
Community Support
Community Support

Hi Greg_Deckler ,thanks for the quick reply, I'll add more.

Hi @Traciicolliins ,

Regarding your problem, you need to create a dummy table to store the results.

Something like this

Measure 4 = 
var _table = ADDCOLUMNS(SUMMARIZE('Table','Table'[ID]),"Column",[Measure 3])
RETURN 
IF(NOT ISBLANK(SELECTEDVALUE('Table'[ID])),[Measure 3],SUMX(_table,[Column]))

vzhouwenmsft_0-1727057725378.png

vzhouwenmsft_1-1727057738426.png

Best Regards,
Wenbin Zhou

 

View solution in original post

2 REPLIES 2
v-zhouwen-msft
Community Support
Community Support

Hi Greg_Deckler ,thanks for the quick reply, I'll add more.

Hi @Traciicolliins ,

Regarding your problem, you need to create a dummy table to store the results.

Something like this

Measure 4 = 
var _table = ADDCOLUMNS(SUMMARIZE('Table','Table'[ID]),"Column",[Measure 3])
RETURN 
IF(NOT ISBLANK(SELECTEDVALUE('Table'[ID])),[Measure 3],SUMX(_table,[Column]))

vzhouwenmsft_0-1727057725378.png

vzhouwenmsft_1-1727057738426.png

Best Regards,
Wenbin Zhou

 

Greg_Deckler
Super User
Super User

@Traciicolliins First, please vote for this idea: https://ideas.powerbi.com/ideas/idea/?ideaid=082203f1-594f-4ba7-ac87-bb91096c742e

This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

Also: https://youtu.be/uXRriTN0cfY
And: https://youtu.be/n4TYhF2ARe8



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors