简体   繁体   English

根据其他列中的条件计算唯一文本值

[英]Count unique text values based on criteria in other column

I have two columns titled "Company" and "Department", example below. 我有两个标题为“公司”和“部门”的列,例如下面的示例。 The third column is what I would like to create, but I am unsure how. 第三列是我想创建的内容,但是我不确定如何创建。 I want the third column to show the number of departments for a given company, and only show that number in the first reference to the company. 我希望第三列显示给定公司的部门数目,而仅在第一个引用该公司的地方显示该数目。

点击这里举例

If you create a helper column in Column C that concatenates your two cells, you can then use a function like this: 如果您在列C中创建一个连接两个单元格的帮助器列,则可以使用如下函数:

=if(countif($C$1:C7,C7)=1,sumif(….),"")

If that's not an option, you'll need to use an Array which is likely not something you want to do either. 如果这不是一个选择,那么您将需要使用一个可能也不是您想要做的事情的数组。

You might be able to capture your requirements with a pivottable too... Not sure. 您也许也可以使用数据透视表捕获您的需求...不确定。

Try this in D2 and fill down. 在D2中尝试此操作并填写。

=IF(COUNTIF(A$2:A2, A2)=1, SUMPRODUCT((A$2:A$999=A2)/(COUNTIFS(B$2:B$999, B$2:B$999&"", A$2:A$999, A2)+(A$2:A$999<>A2))), "")

在此处输入图片说明

You could use a pivot table to get distinct count of column department. 您可以使用数据透视表来获取不同的列部门计数。

While creating the pivot table you need to add the table to the data model so that you expose "distinct count" 在创建数据透视表时,您需要将该表添加到数据模型中,以便暴露“异数”

(one of numerous sources: http://www.howtoexcelatexcel.com/formulas/excel-tip-how-to-count-unique-items-in-excel-pivot-table/ ) (众多来源之一: http : //www.howtoexcelatexcel.com/formulas/excel-tip-how-to-count-unique-items-in-excel-pivot-table/

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

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