简体   繁体   English

带数组条件的求和积

[英]Sumproduct with array condition

I would like to use one sumproduct formula that relies on an array of conditions of cellvalue.我想使用一个依赖于一系列 cellvalue 条件的 sumproduct 公式。 So basically I want to sum something when one of the entries of some cells where found before.所以基本上我想总结一些之前找到的某些单元格的条目之一。

I can make the array of conditions work but not by cell values.我可以使条件数组起作用,但不能通过单元格值起作用。 In example.例如。

Let A1 = "a", A2 = "b", B1 = 1, B2 = 2

Then然后

C1 = Sumproduct((A1:A100={"a"."b"})*(B1:B100)) = 3

works fine, but工作正常,但

C2 = Sumproduct((A1:A100=A1:A2)*(B1:B100)) = ERROR

Is there any way to put {"a"."b"} into a cell or an set of cells?有没有办法将 {"a"."b"} 放入一个单元格或一组单元格中?

Greetings and Thanks for your help, Peter问候并感谢您的帮助,彼得

Disclaimer: I know I could simply write:免责声明:我知道我可以简单地写:

C2 = Sumproduct((A1:A100=A1)*(B1:B100)) + Sumproduct((A1:A100=A2)*(B1:B100))

But I would like to have a solution that is still nice to handle if 10+ conditions are on the list.但是我想要一个解决方案,如果列表中有 10 个以上的条件,它仍然可以很好地处理。

使用 COUNTIF:

=SUMPRODUCT(COUNTIF(A1:A2,A1:A100)*B1:B100)

Use TRANSPOSE to make the cyclic calculation think of A1:A2 as being in a different order (... direction ?) than A1:A100 and B1:B100.使用 TRANSPOSE 使循环计算将 A1:A2 视为与 A1:A100 和 B1:B100 处于不同的顺序(...方向?)。

=SUMPRODUCT((A1:A100=TRANSPOSE(A1:A2))*(B1:B100))

This formula is a true array formula and requires CSE.这个公式是一个真正的数组公式,需要 CSE。

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

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