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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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