[英]How to sum values in excel only if they match a category id in a lookup
Say I have a product category lookup like so: 假设我有一个类似的产品类别查询:
Sheet 1
Product Name | Product Category
--------------------------------------
product 1 | A
product 2 | A
product 3 | B
product 4 | A
product 5 | B
product 6 | C
and I also have a list of purchases which only use Product Name like this: 而且我还列出了仅使用“产品名称”的购买清单:
Sheet 2
Product Name | Purchase Quantity
---------------------------------------
product 1 | 35
product 4 | 10
product 5 | 5
I would like to produce a rollup like this: 我想产生这样的汇总:
Product Category | Purchase Quantity
------------------------------------------
A | 45
B | 5
C | 0
I've tried a variety of ways to solve this like: 我尝试了多种方法来解决此问题,例如:
SUMIF(LOOKUP('Sheet 2'!A2:A6,'Sheet 1'!A:A,'Sheet 2'!B:B), "=A", 'Sheet 2'!B2:B6)
SUMPRODUCT(LOOKUP('Sheet 2'!A2:A6, 'Sheet 1'!A:A, 'Sheet 2'!B:B)="A"*'Sheet 2'!B2:B6)
Excel doesn't like the first one. Excel不喜欢第一个。 It says the formula is incorrect, but I'm not seeing why.
它说公式不正确,但是我不明白为什么。 The second one yields #VALUE.
第二个产生#VALUE。 Any help on this would be much appreciated.
任何帮助,将不胜感激。 Thanks in advance!
提前致谢!
With A in D2, use this as an array formula. 对于D2中的A ,将其用作数组公式。
=SUM(SUMIFS(Sheet2!B$2:B$4, Sheet2!A$2:A$4, IF(Sheet1!B$2:B$7=D2, Sheet1!A$2:A$7)))
Array formulas need to be finished with Ctrl+Shift+Enter, not just Enter. 数组公式需要使用Ctrl + Shift + Enter结束,而不仅仅是Enter。
In my opinion there is no need to use complex formulas for such an easy question. 我认为,对于这样一个简单的问题,无需使用复杂的公式。 Just add another column next to Purchase Quantity sheet 2 to get the Product Category and simply use =SUMIF .
只需在购买数量表2旁边添加另一列即可获得产品类别 ,只需使用= SUMIF即可 。 I have prepare a solution to illustrate my thoughts:
我已经准备了一个解决方案来说明我的想法:
Formula for VLOOKUP: VLOOKUP的公式:
=VLOOKUP(D2,$A$2:$B$7,2,FALSE)
Formula for SUMIF: SUMIF的公式:
=SUMIF($F$2:$F$4,"=" & A10,$E$2:$E$4)
Results: 结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.