Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
157 views
in Technique[技术] by (71.8m points)

google sheets - Sum of every row where two conditions are met

I have two spreadsheets. The first is a list of products, the second is a list of sales.

The products spreadsheet includes four columns: "SKU", "Shipment ID", "Quantity Purchased", and "Remaining Quantity."

     A           B                   C                        D
     SKU      Shipment ID   Qty Purchased   Remaining Qty
1   20121   X2992            40                      38
2   20121   X8483            40                      40
3   71662   X2242            40                      39

The sales spreadsheet includes three columns: "SKU", "Shipment ID", and "Quantity Sold."

     A           B                   C
     SKU      Shipment ID   Qty Sold
1   20121   X2992            1
2   71662   X2242            1
3   20121   X2992            1

I want "Remaining Quantity" to be calculated. Each row of this column should take the "Quantity Purchased" from it's own row and subtract the "Quantity Sold" from the sales spreadsheet for every row where the "SKU" and "Shipment ID" match the "SKU" and "Shipment ID" from its own row. What is the formula for this? (Many formulas are the same in Excel, so I'm tagging Excel as well.)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this formula in the products sheet cell D2 copied down

=C2-ArrayFormula(SUM(IF(Sales!A$2:A$100=A2,IF(Sales!B$2:B$100=B2,Sales!C$2:C$100))))

That assumes data up to row 100 in Sales sheet, adjust as required


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...