Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the count and unique values of a column of comma separated values?

Supposing all I have is the column A below

               +         +
     A         |    B    |    C
+--------------|---------|----------+
               |         |
  X, Y, Z      |   X     |     3
               |         |
  X, Z         |   Y     |     2
               |         |
  X, Y         |   Z     |     2
               +         +

How do I generate columns B and C - where the B column grabs the unique elements from A, and the C column generates a count of those values.

like image 539
Louis93 Avatar asked Dec 21 '13 03:12

Louis93


People also ask

How do I count comma separated values in Excel?

Select the cell you will place the counting result, type the formula =LEN(A2)-LEN(SUBSTITUTE(A2,",","")) (A2 is the cell where you will count the commas) into it, and then drag this cell's AutoFill Handle to the range as you need.

How can I count the number of comma separated values in a string?

SQL Pattern: How can I count the number of comma separated values in a string? (Community) Basically, you replace all occurrences of , with an empty string "" , then subtract its LENGTH from the LENGTH of the unadulterated string, which gives you the number of , characters.

How do I count the number of unique values in a column?

In this case, you can use a combination of SUM, IF and COUNTIF functions to count unique values in Excel. To count unique values, enter the formula =SUM(IF(COUNTIF(range, range)=1,1,0)) in the desired cell.

Is there a way to count only unique values in Excel?

You can use the combination of the SUM and COUNTIF functions to count unique values in Excel. The syntax for this combined formula is = SUM(IF(1/COUNTIF(data, data)=1,1,0)). Here the COUNTIF formula counts the number of times each value in the range appears.


1 Answers

=ArrayFormula(QUERY(TRANSPOSE(SPLIT(JOIN(",",A:A),",")&{"";""}),"select Col1, count(Col2) group by Col1 label count(Col2) ''",0))

QUERY function

TRANSPOSE function

SPLIT function

JOIN function

like image 142
AdamL Avatar answered Sep 23 '22 23:09

AdamL