简体   繁体   English

在sumproduct函数中使用vlookup或索引匹配

[英]Using a vlookup or index match inside a sumproduct function

例

I have two 2-D arrays that relate to engines. 我有两个与引擎有关的二维数组。 The first table classifies an Engine as either a or as b . 第一个表将Engine分类为ab The second table has a numerical count value for each of the engines. 第二个表具有每个引擎的数字计数值。

I want to calculate the number of engines for each label. 我想计算每个标签的引擎数量。 Here, label a has a count of 40 and label b has a count of 300. 在这里,标签a的计数为40,标签b的计数为300。

I thought the following formula would work... 我认为以下公式会起作用...

=SUMPRODUCT(
            --(E3=VLOOKUP(A11:A17,A2:B8,2,0)),
            B11:B17
           )

...but it does not! ...但事实并非如此!

Why can't I use a vlookup inside a sumproduct array formula? 为什么我不能在sumproduct数组公式中使用vlookup? Index-match also doesn't work. 索引匹配也不起作用。

I can't append a new column to the second table with a vlookup forumla that references the first table. 我无法使用引用第一个表的vlookup forumla将新列追加到第二个表。

Use LOOKUP: 使用LOOKUP:

=SUMPRODUCT(($B$2:$B$8=E3)*LOOKUP($A$2:$A$8,$A$11:$A$17,$B$11:$B$17))

在此处输入图片说明


To do it with unsorted data use this array formula: 要对未排序的数据执行此操作,请使用以下数组公式:

=SUM(SUMIF($A$11:$A$17,IF($B$2:$B$8=E3,$A$2:$A$8),$B$11:$B$17))

Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. 作为数组公式,退出编辑模式时必须使用Ctrl-Shift-Enter而不是Enter进行确认。 If done correctly then Excel will put {} around the formula. 如果操作正确,则Excel会将{}放在公式周围。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM