繁体   English   中英

Excel:使用SUMPRODUCT在多个条件下计算唯一值

[英]Excel: count unique values using SUMPRODUCT with multiple conditions

好的,我有一个求和产品,可以为我提供一列中唯一值的计数:

=SUMPRODUCT((F2:F38<>"")/COUNTIF(F2:F38,F2:F38))

因此,如果我有数字: 1, 2, 3, 1, 5, 6, 2, 5, 2它将返回5

但是我要做的是根据另一个数字来计算唯一值的数量,例如:

Name:             Sales:
Mike              2
Bob               1
Gary              1
Mike              5
Bob               6
Gary              1
Mike              3
Bob               4
Gary              2
Mike              1
Bob               2
Gary              6
Mike              3
Bob               1
Gary              1
Mike              1
Bob               3
Gary              4

可以说,“名称” Mike有4unique values for "Name" Bob, and 5个unique values for "Name" Bob, and unique values for "Name" Gary. This is because for "Name" Mike there are the numbers 4个unique values for "Name" Gary. This is because for "Name" Mike there are the numbers unique values for "Name" Gary. This is because for "Name" Mike there are the numbers 2 5 3 1个 3 1 , so the unique numbers are 2 5 3 1 and therefore the count would return 4`。

有办法吗?

这是一个解决方案。

在底部插入一个单元格,其中包含您要为其计算唯一值的值。因此在工作表底部添加“ Gary”。 在“销售”列的右侧创建另一个列,称为“ NameValue”。 在此列中创建一个公式:

=IF(A2=$A$10,B2,"") <-Where $A$10 is the location of "Gary"

然后在新列的底部插入以下公式:

=SUM(IF(C2:C6<>"",1/COUNTIF(C2:C6, C2:C6), 0)) <-Where C2:C6 is your range we just create from above.

在键入此公式时,您可能需要按Ctrl + Shift + Enter。现在,您可以将A12的值更改为名称列中的任何值,这将吐出唯一计数。

暂无
暂无

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

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