how do I count the unique text entries in a column
I want to count thenumber of unique text entries in a column how do I do that?
Mac mini, OS X Mavericks (10.9.1)
I want to count thenumber of unique text entries in a column how do I do that?
Mac mini, OS X Mavericks (10.9.1)
You can usethe match() function wrapped in iferror() and if() like this.
If the data is in column A then add a formula to column B. Assuming the first row is a header...
B2=IF(IFERROR(MATCH(A2, $A$1:A1,0), 0)>0,"", MAX($B$1:B1)+1)
this is shorthand for select cell B2, then type (or copy and paste the formula from here:
=IF(IFERROR(MATCH(A2, $A$1:A1,0), 0)>0,"", MAX($B$1:B1)+1)
select B2, copy
select column B, then hold the <command> key while you click cell B1 (to unselect), paste
D1=MAX(B)
cell D1 (in this example) indicates the number of distinct items.
If you just need the count (and not a list of unique values, in which case you would start with Wayne's setup and add an additional table) then you could also do this:
Formula in B2, copied down, is =IF(COUNTIF($A$1:A2,A2)=1,1,"")
This inserts a 1 for the first occurrence of a value, otherwise nothing.
Then, in B1, the forumula =SUM(B) gives the count of unique values.
SG
Or, if you will need to do this on different documents, you can copy this script into AppleScript Editor, select the cells in whichever document you are working on, and run. No need to set up the formulas and extra column again.
SG
--select range of cells, run; provides count of distinct values
tell application "Numbers" to tell the front document to tell active sheet
set selectedTable to (the first table whose class of selection range is range)
tell selectedTable to tell the selection range
set distinctValues to {}
repeat with aCell in its cells
tell aCell
if its value is not in distinctValues then ¬
copy its value to the end of distinctValues
end tell
end repeat
return count of distinctValues
end tell
end tell
--end of script
how do I count the unique text entries in a column