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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
mageshraja
Frequent Visitor

Multiple line Qty Subtraction from Single Data

Hi ,

Hope this would be simple doubt. But I need help to crack the solution in Power bi

Have Two tables:

Table 1: Same part # stock received on muliple dates / Unique Ref. 

Table 2: Usage of the parts without any reference

Output Needed :

1. Each line in Table 1 should have a new coulum with the Qty used, which should not be greater than the received qty

2. The Qty considereded for the previous line from table should be deducted for the next line calculation

Table 1  
Unique Ref IDPart #Received Qty
ID1A2000
ID2A2000
ID3A2000
ID4A2000
ID5B2500

 

Table 2 
Part #Qty Used
A7000
B5000

 

OutPut Expected   
Unique Ref IDPart #QtyQty Used (Table 2)
ID1A20002000
ID2A20002000
ID3A20002000
ID4A20001000
ID5B25002500

 

Thanks

Mak

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

Try like new columns

Col1 = sumx(filter(table1, table1[Part #]=earlier(table1[Part #]) && table1[Unique Ref ID]<=earlier(Unique Ref ID])),table[Received Qty])
col2 = sumx(filter(table2, table1[Part #]=table2[Part #]),table2[Qty Used])
col3 = if((col2-col1)<col2,(col2-col1),col2)

 

Appreciate your Kudos.

 

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

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

Try like new columns

Col1 = sumx(filter(table1, table1[Part #]=earlier(table1[Part #]) && table1[Unique Ref ID]<=earlier(Unique Ref ID])),table[Received Qty])
col2 = sumx(filter(table2, table1[Part #]=table2[Part #]),table2[Qty Used])
col3 = if((col2-col1)<col2,(col2-col1),col2)

 

Appreciate your Kudos.

 

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

Hi Amit,

It works. Thanks for the solution.

 

Regards,

Mak

 

Greg_Deckler
Community Champion
Community Champion

First, can you guarantee that Unique Ref ID will always sort alphabetically such that the earliest "instances" are always alphabetically "less" than later "instances". If that cannot be guaranteed, do you have a date column or index column where you can distinguish "earlier" from "later"?

 

Because if you don't, this will be difficult if not impossible.

 



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi Greg,

Yes , the unique ref ID are sequenced numeric data which can be sorted from earliest. In that case what solution can support in this case.

 

Thanks,

Magesh

 

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors