简体   繁体   English

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

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

Ok, I have a sum product working to give me the count of unique values in a column: 好的,我有一个求和产品,可以为我提供一列中唯一值的计数:

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

So if I have the numbers: 1, 2, 3, 1, 5, 6, 2, 5, 2 it would return 5 . 因此,如果我有数字: 1, 2, 3, 1, 5, 6, 2, 5, 2它将返回5

But what I want to do is count the number of unique values based upon another number, eg: 但是我要做的是根据另一个数字来计算唯一值的数量,例如:

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

It would say that there are 4 unique values for "Name" Mike, 5 unique values for "Name" Bob, and 4 unique values for "Name" Gary. This is because for "Name" Mike there are the numbers 可以说,“名称” 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 unique values for "Name" Gary. This is because for "Name" Mike there are the numbers 2 5 5 3 3 1 1个 3 3 1 , so the unique numbers are 2 1 , so the unique numbers are 2 5 5 3 3 1 and therefore the count would return 4`. 1 and therefore the count would return 4`。

Is there a way of doing this? 有办法吗?

Here's one solution. 这是一个解决方案。

Insert a cell at the bottom with the value you are trying to count unique for.. So "Gary" at the bottom of your sheet. 在底部插入一个单元格,其中包含您要为其计算唯一值的值。因此在工作表底部添加“ Gary”。 Create another column to the right of the Sales Column Called "NameValue". 在“销售”列的右侧创建另一个列,称为“ NameValue”。 Create a formula in this column: 在此列中创建一个公式:

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

Then at the bottom of the new column insert this formula: 然后在新列的底部插入以下公式:

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

You might need to press Ctrl+Shift+enter when you type this formula in. Now you can change the value of A12 to any value in the name column and it will spit out the unique count. 在键入此公式时,您可能需要按Ctrl + Shift + Enter。现在,您可以将A12的值更改为名称列中的任何值,这将吐出唯一计数。

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

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