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! Learn more

Reply
mantasp
Frequent Visitor

SUM from DAX

Hello,
I have this code to get value by max date in rows.
My problem: how can i sum all of this values? 
 
Code:
sales_latest = Var Max_date = MAX(FuelHistory[EventTime])
                var Latest_sales = CALCULATE(SUM(FuelHistory[Fuel]), FuelHistory[EventTime]=Max_date)
                Return Latest_sales
 
Please help!
mantasp_0-1667386706915.png

 

1 ACCEPTED SOLUTION

@mantasp Right, so you have a working measure for the rows. What you need to do then is (easiest way) create a new measure that uses ISINSCOPE or HASONEVALUE. If you HASONEVALUE for a certain column then you are in a row and return your original measure. If you are not in a row (total) you then have to SUMMARIZE your data exactly as it appears in your table with your measure tacked on as a calculation and then you do a SUMX across that.

 

Can't be more specific because you haven't provided sample data, what your tables and columns are called and all that.

 

And, if you find this incredibly frustrating, then vote for the idea I have linked in my signature.



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

4 REPLIES 4
mantasp
Frequent Visitor

Thank you, Greg Deckler

mantasp
Frequent Visitor

@Greg_Deckler thanks for your replay and for your websites.

First I have to find value by latest time and then sum it. 

1 ID have 1-5 rows with price and  I need use only latest by date. My code is working, but when I want to sum it I can't

mantasp_0-1667391919537.png

 

@mantasp Right, so you have a working measure for the rows. What you need to do then is (easiest way) create a new measure that uses ISINSCOPE or HASONEVALUE. If you HASONEVALUE for a certain column then you are in a row and return your original measure. If you are not in a row (total) you then have to SUMMARIZE your data exactly as it appears in your table with your measure tacked on as a calculation and then you do a SUMX across that.

 

Can't be more specific because you haven't provided sample data, what your tables and columns are called and all that.

 

And, if you find this incredibly frustrating, then vote for the idea I have linked in my signature.



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...
Greg_Deckler
Community Champion
Community Champion

@mantasp 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



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.