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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

How to calculate a cumulative sum by id's groups?

I have the following data: GOAL_ID and PLAN, I would like to create a measure that would result in a column with the same behavior as the column "CUMULATIVE SUM". SOMEONE?

Capturar.PNG

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

To do that measure, you would need one more column like an index or a date to do the cumulative calculation as a function of.  Your pic shows 10 rows of data.  Assuming you added an Index column to the table going from 1 to 10, this measure would give you your desired result.  I put some mock data in a table called 'Goal'.

 

Cumulative Total Same GoalID = var currentindex = SELECTEDVALUE('Goal'[Index])
return CALCULATE(SUM('Goal'[Plan]), ALL('Goal'), VALUES('Goal'[GoalID]), 'Goal'[Index] <= currentindex)

 

GoalID.png

 

If this works for you, please mark it as the solution.  Kudos are great too.  

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

8 REPLIES 8
Slambrecht2022
Regular Visitor

I have a similar issue. I want to calculate the **bleep** unit_price_tax_incl per id_order, but I'm doing something wrong...

Can someone please help me out? 

 

The formula doesn't give an error, but it doesn't give results either. 

 

Cumulative Total Same OrderID = var currentindex = selectedvalue('sb_shop16 ps_order_detail'[Index])
return calculate(sum('sb_shop16 ps_order_detail'[total_price_tax_incl]),ALL('sb_shop16 ps_order_detail'),VALUES('sb_shop16 ps_order_detail'[id_order]),'sb_shop16 ps_order_detail'[Index]<=currentindex)

 

Slambrecht2022_0-1641919345031.png

 

Thanks for your help!

mahoneypat
Microsoft Employee
Microsoft Employee

To do that measure, you would need one more column like an index or a date to do the cumulative calculation as a function of.  Your pic shows 10 rows of data.  Assuming you added an Index column to the table going from 1 to 10, this measure would give you your desired result.  I put some mock data in a table called 'Goal'.

 

Cumulative Total Same GoalID = var currentindex = SELECTEDVALUE('Goal'[Index])
return CALCULATE(SUM('Goal'[Plan]), ALL('Goal'), VALUES('Goal'[GoalID]), 'Goal'[Index] <= currentindex)

 

GoalID.png

 

If this works for you, please mark it as the solution.  Kudos are great too.  

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Yes, it worked, thank you very much, just one more question, does the table show the total accumulated sum? @mahoneypat 

Yes. It shows the sum of the Goal column for the same GoalID with the same or lower index values.  Typically you would do cumulative measures using a date field, but index is fine too.

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thank you so much! It was a great help. The only thing I would lack is the sum at the end that does not come out. Thank you

Anonymous
Not applicable

@mahoneypat I put the fields in a table, but it didn't create the total row. Anyway, I am very grateful for the help.

amitchandak
Super User
Super User

@Anonymous , Use quick measure and create running total

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you, this was the one I served, and pretty quickly. The only thing to keep in mind is that the date field should be given the "Date" and not "Date Hierarchies", but it is not shown cumulatively.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.