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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
georgec96
Helper II
Helper II

Cumulative sum based on other columns

Hi everyone,

I've been struggling to write a calculated column to solve the following issue.

 

I've got 4 columns: SKU,PO,Qty ordered and Qty on backorder. I need to create a column called "can_clear_backorders", that will calculate the amount of backorders a PO can clear based on the qty ordered but this needs to be a cumulative sum and it also needs to reset when there is a new value in column SKU.

 

Any ideas how can I achive this? Sorry if my explanation is not clear enough, I've attached an image with the expected result as an example.

 

georgec96_0-1673971473271.png

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @georgec96 

 

You can try the following methodsYou need to add an index column to Power Query first.

Column:

Max Oty on backorder = MAXX(FILTER('Table',[SKU]=EARLIER('Table'[SKU])),[Qty on backorder])
Cumulative = CALCULATE(SUM('Table'[Qty ordered]),FILTER('Table',[SKU]=EARLIER('Table'[SKU])&&[Index]<EARLIER('Table'[Index])))
Result = 
SWITCH(TRUE(),
 [Cumulative] = BLANK ()&& [Qty ordered] <= [Qty on backorder], [Qty ordered],
 [Cumulative] = BLANK ()&& [Qty ordered] > [Qty on backorder],[Qty on backorder],
 [Max Oty on backorder]-[Cumulative]<0,0,
 [Qty ordered]<[Cumulative],[Qty ordered],[Max Oty on backorder]-[Cumulative])

vzhangti_0-1674114725648.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

View solution in original post

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @georgec96 

 

You can try the following methodsYou need to add an index column to Power Query first.

Column:

Max Oty on backorder = MAXX(FILTER('Table',[SKU]=EARLIER('Table'[SKU])),[Qty on backorder])
Cumulative = CALCULATE(SUM('Table'[Qty ordered]),FILTER('Table',[SKU]=EARLIER('Table'[SKU])&&[Index]<EARLIER('Table'[Index])))
Result = 
SWITCH(TRUE(),
 [Cumulative] = BLANK ()&& [Qty ordered] <= [Qty on backorder], [Qty ordered],
 [Cumulative] = BLANK ()&& [Qty ordered] > [Qty on backorder],[Qty on backorder],
 [Max Oty on backorder]-[Cumulative]<0,0,
 [Qty ordered]<[Cumulative],[Qty ordered],[Max Oty on backorder]-[Cumulative])

vzhangti_0-1674114725648.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

amitchandak
Super User
Super User

@georgec96 , You back order logic is not clear.

 

But windows function with partitioned by can help

Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc

https://www.youtube.com/watch?v=cN8AO3_vmlY&t=31980s

 

The information you have provided is not making the problem clear to me. Can you please explain with an example.

Appreciate your Kudos.

 

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

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

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