How to find how many unique values are associated with a word in excel

大城市里の小女人 提交于 2020-01-17 03:46:35

问题


Say I have one column called colors with 1000 cells populated with values. Some of the cells have the word blue in it. In another column I have unique identifiers that correspond with the colors column. For example Blue can have a value associated to it of 01, 02, 04, or 05. The word blue appears 20 times within my name column. What is one way I can find how many unique identifiers are associated with the word blue?

In the example listed above the answer should return 4.

The current method I am using to accomplish this is by using a pivot table. I filter out any value in the name column that doesnt include the word blue. Then I count all the unique identifiers that appear in my pivot table.

EDIT: Notice how blue appears 8 times, but it only has the values 1, 2, 3, and 4 associated with it. How can I create a function that finds out how many values are associated with blue?


回答1:


One option:

In Excel versions that support Power Pivot, add the data to the data model, build a pivot table and use the "Distinct Count" as the aggregation of the values.

Without Power Pivot, build a regular pivot table with the value field (bad wording of the field, sorry) nested under the colors field, then use Countif on the color column of the pivot table.




回答2:


Assuming your data is located at A1:B21 try this:

Enter the following headers at D1:F1

Enter these ArrayFormulas

FormulaArrays are entered pressing CTRL+SHIFT+ENTER simultaneously, you shall see { and } around the formula if entered correctly

In D2 - Returns an unique combined list of Colors & Values:

=IFERROR(
INDEX($A$2:$A$21&$B$2:$B$21,
MATCH(0,COUNTIF($D$1:$D1,$A$2:$A$21&$B$2:$B$21),0)*1),"")

In E2 - Returns an unique list of Colors:

=IFERROR(
INDEX($A$2:$A$21,
MATCH(0,COUNTIF($E$1:$E1,$A$2:$A$21),0)*1),"")

In F2 - Returns the count of combined Colors & Values for each Color:

=COUNTIF($D$2:$D$21,$E2&"*")

Then copy the ArrayFormulas in D2:F2 till last row of data (i.e. row 21)

Column D could be hidden if required...




回答3:


In addition to the answer in the first comment, you can filter it with something like this (not tested):

= SUMPRODUCT( IFERROR(1 / COUNTIFS(A2:A21, "Blue", B2:B21, B2:B21), 0) )


来源:https://stackoverflow.com/questions/41252238/how-to-find-how-many-unique-values-are-associated-with-a-word-in-excel

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