Count unique text values based on criteria in other column

蓝咒 提交于 2021-02-04 21:53:04

问题


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.

Click here for example


回答1:


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))), "")




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/51051962/count-unique-text-values-based-on-criteria-in-other-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!