简体   繁体   中英

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:

=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.

=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/ )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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