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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
BryanJun
Frequent Visitor

Running subtract in group by using first row value in other column

I have a table that contain item, qty_on_hand, and request_material.

There is a problem that my qty_on_hand is repeating and I only need one of these row to deduct the request material.

Is there any method can calculate the running balance in the same item group by using qty_on_hand deduct request material? (running balance can be negative since it can be shortage)

 

Table

Itemqty_on_handrequest_material
A10030
A10050
A10010
B200100
B200100
B200150

 

Above table shows qty_on_hand repeating, but i just need one of them to deduct the request_material (e.x: Item A only have 100 quantity on hand but it shows 3 times)

 

My expected output as below:

 

Table

Itemqty_on_handrequest_materialRuning Total
A1003070
A1005020
A1001010
B200100100
B2001000
B200150-150
1 ACCEPTED SOLUTION

Hi,

These calculated column formulas work

Cumulative material request = CALCULATE(SUM('Item'[material request]),FILTER('Item','Item'[Item]=EARLIER('Item'[Item])&&'Item'[Due date]<=EARLIER('Item'[Due date])))
Bal = 'Item'[stock]-'Item'[Cumulative material request]

The Cumulative material request entries in few rows are the same because the Due Date is the same.  In the Query Editor Group the Stock and material request by Item and Due Date.  For Stock, select the function as Min and for material, as SUM.

Hope this helps.

Untitled.png  


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

Do you have a Date column?  If yes, then it becomes simple to solve.  Also, it looks like you want a calculated column formula solution (and not a measure).  Am i correct?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

yes, this table has contain a date column and it is better to deduct the earlier date first as well.

I'm prefer to create a new column in this table.

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi, here's the PBI file.

you can access by this link : item.pbix

Hi,

These calculated column formulas work

Cumulative material request = CALCULATE(SUM('Item'[material request]),FILTER('Item','Item'[Item]=EARLIER('Item'[Item])&&'Item'[Due date]<=EARLIER('Item'[Due date])))
Bal = 'Item'[stock]-'Item'[Cumulative material request]

The Cumulative material request entries in few rows are the same because the Due Date is the same.  In the Query Editor Group the Stock and material request by Item and Due Date.  For Stock, select the function as Min and for material, as SUM.

Hope this helps.

Untitled.png  


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

Thanks a lot, this solution is near to my actual needed. 

Based your solution, i create an index column based on the due date.

Then make some changes on your code as below:

 

Cumulative material request = CALCULATE(SUM('Item'[material request]),FILTER('Item','Item'[Item]=EARLIER('Item'[Item])&&'Item'[Index]<=EARLIER('Item'[Index])))

 

Bal = 'Item'[stock]-'Item'[Cumulative material request]

This make the running result appear in the 'bal' column. 

 

BryanJun_0-1671511454320.png

 

You are welcome.  If my previous reply helped, please mark that reply as Answer.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.