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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
DataVitalizer
Super User
Super User

Sum of previous values (no date column)

Hi Community,

 

I am working on the sample below , the objective is to calculatd in new column the Sum of Amounts where ID < Current_ID, in the right side the result I am supposed to get:

 

Data.png

Here is my Dax measure but it returns an empty column

Measure =

Var currentID=SUM('Table'[ID])

Return

SUMX(FILTER('Table','Table'[ID]<currentID),'Table'[Amount])

 

Thank you in advance 

1 ACCEPTED SOLUTION

Hello @Greg_Deckler

I confirm that the updated DAX returns the value taking into account only key1 while key 2 is excluded.

Once I expanded the Key2 data I got incorrect values:

Data 5.png

So I tried to add key2 to the extent, even though I didn't get the right values

Measures 
VAR currentID-MAX('DATA'[ID])
VAR key1 to MAX('DATA'[Key 1])
VAR Key2 MAX(DATA[Clave 2])
Return
SUMX(FILTER(ALL('DATA'),'DATA'[Key 1]-key1 && 'DATA'[Key 2]-Key2 &&'DATA'[ID]<currentID),'DATA'[Amount])

Thank you in advance

View solution in original post

8 REPLIES 8
amitchandak
Super User
Super User

@DataVitalizer , new column

SUMX(FILTER('Table','Table'[ID]< earlier('Table'[ID])),'Table'[Amount])

 

new Measure

SUMX(FILTER(all('Table'),'Table'[ID]< max('Table'[ID])),'Table'[Amount])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi,

Thank you @Greg_Deckler , @amitchandak  for your quick reply.

I've tried both suggested measures, here below what I got:

Data 3.png

 

The returned values are different than the target, here i tried to clarify more the need:

Data 2.png

 

Thank you in advance.

@DataVitalizer - I updated my post after I originally posted, please check again, I took Key1 into account.



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...

Hello @Greg_Deckler

I confirm that the updated DAX returns the value taking into account only key1 while key 2 is excluded.

Once I expanded the Key2 data I got incorrect values:

Data 5.png

So I tried to add key2 to the extent, even though I didn't get the right values

Measures 
VAR currentID-MAX('DATA'[ID])
VAR key1 to MAX('DATA'[Key 1])
VAR Key2 MAX(DATA[Clave 2])
Return
SUMX(FILTER(ALL('DATA'),'DATA'[Key 1]-key1 && 'DATA'[Key 2]-Key2 &&'DATA'[ID]<currentID),'DATA'[Amount])

Thank you in advance

Hi Community,

Any suggestions to solve that issue ?

@Greg_Deckler , @amitchandak  any updates 🙂

 

Thank you in advance

Hi @DataVitalizer ,

 

How about the result after you follow the suggestions mentioned in my original post?

Could you please provide more details or expected result about it If it doesn't meet your requirement?

If you've fixed the issue on your own please kindly share your solution. If the above posts help, please kindly mark it as a solution to help others find it more quickly.

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @DataVitalizer ,

 

We can create a measure to meet your requirement.

 

Measure = 
CALCULATE(SUM('Table'[Amount]),FILTER(ALLSELECTED('Table'),'Table'[Key 1]=MAX('Table'[Key 1]) && 'Table'[ID]<MAX('Table'[ID])))

 

sum1.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

BTW, pbix as attached.

Greg_Deckler
Super User
Super User

@DataVitalizer 

 

 

Measure =
Var currentID=MAX('Table'[ID])
VAR key1 = MAX('Table'[Key1])
Return
SUMX(FILTER(ALL('Table'),'Table'[Key1]=key1 && 'Table'[ID]<currentID),'Table'[Amount])

 

 



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 MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.