简体   繁体   English

如何使用两个条件在Excel中计算唯一值

[英]How to count unique values in Excel with two conditions

I know there is already a question that has been answered about counting uniques with a condition ( Count Unique values with a condition ), but I want to know how to count uniques in a column with TWO conditions. 我知道已经有一个问题已经回答有关使用条件计算唯一身份(使用条件计算唯一值 ),但我想知道如何在具有两个条件的列中计算唯一身份。

I have a dataset with dates of locations created as well as city. 我有一个数据集,其中包含创建位置的日期以及城市。 Each location has an owner and sometimes an owner can have multiple locations so I want to count unique owners by city and month (both already exist as columns). 每个位置都有一个所有者,有时一个所有者可以有多个位置,所以我想按城市和月份计算唯一所有者(两者都已作为列存在)。

How can I do this? 我怎样才能做到这一点?

The formula I suggested in the link is this 我在链接中建议的公式是这个

=SUM(IF(FREQUENCY(IF(B2:B100=1,IF(A2:A100<>"",MATCH(A2:A100,A2:A100,0))),ROW(A2:A100)-ROW(A2)+1),1))

that counts different values in A2:A100 if B2:B100 =1 如果B2:B100 = 1,则计算A2:A100不同值A2:A100

You can just add more IF s with more conditions, making sure you get the requisite number of parentheses in the correct locations, eg for the number of different owners by city and month try this version for March in Chicago 您可以添加更多IF以及更多条件,确保您在正确的位置获得必要数量的括号,例如,按城市和月份的不同所有者的数量在Chicago尝试此版本的March

=SUM(IF(FREQUENCY(IF(City="Chicago",IF(Month="March",IF(Owner<>"",MATCH(Owner,Owner,0)))),ROW(Owner)-MIN(ROW(Owner))+1),1))

confirmed with CTRL + SHIFT + ENTER CTRL + SHIFT + ENTER确认

To add to Barry's answer: you don't have to nest the IF's as that gets messy quickly. 要添加到Barry的答案:你不必嵌入IF,因为它很快就会变得混乱。 You can simply multiply them together like this: 您可以简单地将它们相乘:

IF((City="Chicago)*(Month="March"),...)

It's much easier to add variables that way and keep track of parenthesis. 以这种方式添加变量并跟踪括号更容易。

If you are using Excel 2013, there is a very simple approach w/o any formulas, 如果您使用的是Excel 2013,那么有一种非常简单的方法,无需任何公式,

Consolidate (excel feature under DATA), arrange in a way the City names are on left, and owner names next column to right, on top row put the labels of city and owner, then select the data and click both (header and left row) options, and for the operation from top of the dialogue choose count. 合并(DATA下的excel功能),以左侧的城市名称排列,右侧的所有者名称排列,在顶行放置城市和所有者的标签,然后选择数据并单击两者(标题和左侧行) )选项,并从对话顶部操作选择计数。

You should have the report you are looking for. 你应该有你想要的报告。

Note: You also might need to remove duplicates also you can do so based on two column conditions. 注意:您也可能需要删除重复项,也可以根据两个列条件执行此操作。

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

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