Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Count of Distinct Values

Posted on 2013-12-10
Medium Priority
299 Views
I have a column that might contain the following rows:
1
1
2
4
3
2
1
4
3
2
1
2
3
As you can see, in this case, there are 4 distinct values. I want a summary cell that displays the number of distinct values (4). I prefer (require) this to be a formula vs. VBA code.
0
Question by:dbbishop
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
• 4
• 3
• 2

LVL 15

Author Comment

ID: 39710130
p.s. the data is not sorted.
0

LVL 9

Expert Comment

ID: 39710137
If your values are in column A from rows 1 through to 13 then use this formula.

=SUMPRODUCT((A1:A13<>"")/COUNTIF(A1:A13,A1:A13&""))
0

LVL 6

Accepted Solution

JJSmith earned 2000 total points
ID: 39710152
Assuming the column is A, then:

=SUM(IF(FREQUENCY(A1:A12,A1:A12)>0,1))

should do the trick - it's a little bit of a cheat as the data and bin ranges are the same - but has the desired outcome.
0

LVL 9

Expert Comment

ID: 39710156
There are 13 rows in his data set so you would be missing the final value, not that it affects the count in this example.
0

LVL 6

Expert Comment

ID: 39710179
My bad - but it's the formula rather than the data range that was requested.
0

LVL 9

Expert Comment

ID: 39710184
Indeed and it was already provided!
0

LVL 15

Author Closing Comment

ID: 39710402
Works like a champ.
0

LVL 9

Expert Comment

ID: 39710660
It would be useful to know what it was that you didn't like about the solution which was offered first (my one)?
0

LVL 15

Author Comment

ID: 39711309
I tried both. Yours worked for a short list, but when I tried it with 40,000 rows, which was the real data, the solution posted by JJSmith was CONSIDERABLY faster. Furthermore, with the increased row count, yours did not return the correct value (consistently returned 0). I tried yours with 10,000 rows and it returned the correct value, but 20,000 rows returned 0. Don't know where the cutoff was.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will diâ€¦
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabilâ€¦
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
###### Suggested Courses
Course of the Month5 days, 10 hours left to enroll

#### 660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.