Create a unique distinct list and sort by occurrances from large to small
Question:
How do I create a new unique distinct list from a column. I also want the list sorted from large to small by the number of occurrances?
Answer:
Array formula in cell D3:
How to create an array formula
- Copy (Ctrl + c) and paste (Ctrl + v) array formula into formula bar. See picture below.
- Press and hold Ctrl + Shift.
- Press Enter once.
- Release all keys.
Named ranges
List (B3:B14)
- Select cell range B3:B14.
- Type List in Name Box. See picture above.
How to copy array formula in cell D3
- Select cell D3
- Copy cell (Ctrl + c)
- Select cell range D4:D8
- Paste (Ctrl + v)
Formula in E3:
=COUNTIF(List, D3)
Explaining array formula in cell D3
Step 1 - Remove duplicates
=INDEX(List, MATCH(LARGE(IF(COUNTIF($D$2:D2, List)=0, COUNTIF(List, List), ""), 1), COUNTIF(List, List)*(COUNTIF($D$2:D2, List)=0), 0))
IF(COUNTIF($D$2:D2, List)=0, COUNTIF(List, List), "")
becomes
IF(COUNTIF("List sorted by occurrances", {"DD";"AA";"AA";"BB";"AA"; "DD";"EE";"AA";"BB";"EE";"CC";"EE"})=0, COUNTIF({"DD";"AA";"AA";"BB";"AA"; "DD";"EE";"AA";"BB";"EE";"CC";"EE"}, {"DD";"AA";"AA";"BB";"AA"; "DD";"EE";"AA";"BB";"EE";"CC";"EE"}), "")
becomes
IF({0;0;0;0;0;0;0;0;0;0;0;0}=0, {2;4;4;2;4;2;3;4;2;3;1;3}, "")
becomes
IF({TRUE;TRUE;TRUE;TRUE;TRUE; TRUE;TRUE;TRUE;TRUE;TRUE;TRUE;TRUE}, {2;4;4;2;4;2; 3;4;2;3;1;3}, "")
and returns
{2;4;4;2;4;2;3;4;2;3;1;3}
Step 2 - Find maximum value
=INDEX(List, MATCH(LARGE(IF(COUNTIF($D$2:D2, List)=0, COUNTIF(List, List), ""), 1), COUNTIF(List, List)*(COUNTIF($D$2:D2, List)=0), 0))
LARGE(IF(COUNTIF($D$2:D2, List)=0, COUNTIF(List, List), ""), 1)
becomes
LARGE({2;4;4;2;4;2;3;4;2;3;1;3}, 1)
and returns 4.
Step 3 - Return the relative position of an item in an array that matches a specified value
=INDEX(List, MATCH(LARGE(IF(COUNTIF($D$2:D2, List)=0, COUNTIF(List, List), ""), 1), COUNTIF(List, List)*(COUNTIF($D$2:D2, List)=0), 0))
MATCH(LARGE(IF(COUNTIF($D$2:D2, List)=0, COUNTIF(List, List), ""), 1), COUNTIF(List, List)*(COUNTIF($D$2:D2, List)=0), 0)
becomes
MATCH(4, COUNTIF(List, List)*(COUNTIF($D$2:D2, List)=0), 0)
becomes
MATCH(4, {2;4;4;2;4;2;3;4;2;3;1;3}), 0)
and returns 2.
Step 4 - Return a value or reference of the cell at the intersection of a particular row and column, in a given range
=INDEX(List, MATCH(LARGE(IF(COUNTIF($D$2:D2, List)=0, COUNTIF(List, List), ""), 1), COUNTIF(List, List)*(COUNTIF($D$2:D2, List)=0), 0))
becomes
=INDEX(List, 2)
becomes
=INDEX({"DD";"AA";"AA";"BB";"AA";"DD"; "EE";"VV";"BB";"EE";"VV";"EE"}, 2)
and returns "AA".
Download excel example file.
unique-sorted-by-occurances.xls
(Excel 97-2003 Workbook *.xls)
Functions in this article:
ROW(reference) Returns the rownumber of a reference
LARGE(array,k) returns the k-th largest row number in this data set
MATCH(lookup_value;lookup_array; [match_type])
Returns the relative position of an item in an array that matches a specified value
COUNTIF(range,criteria)
Counts the number of cells within a range that meet the given condition
INDEX(array,row_num,[column_num])
Returns a value or reference of the cell at the intersection of a particular row and column, in a given range
Related posts:
Create and sort distinct list by adjacent cell value size
How to create a unique distinct list where other columns meet two criteria
How to automatically create a unique distinct list and remove blanks
Create unique distinct list sorted based on text length using array formula in excel



















hi
how to find missing numbers range 1-49 from following line
06 11 17 33 37 47
05 06 12 14 22 34
03 20 35 41 48 49
08 12 17 24 25 45
03 10 18 22 29 45
13 16 22 23 39 43
03 10 17 31 36 45
02 24 32 37 43 49
10 16 27 28 29 42
02 35 38 39 40 48
08 23 34 36 44 47
09 16 21 26 28 29
10 15 32 33 39 41
04 11 20 33 43 45
01 08 21 22 27 36
04 12 25 36 43 49
09 12 23 26 34 43
19 23 24 30 34 46
08 17 20 21 31 45
04 06 17 27 36 48
07 08 19 28 32 41
13 17 26 30 39 47
10 15 20 29 32 43
13 19 22 25 27 45
04 09 19 21 25 42
01 12 24 37 44 47
08 19 31 34 38 42
11 14 31 33 34 47
19 22 32 33 38 48
08 13 14 20 37 40
03 08 10 13 41 47
01 02 14 16 26 30
30 34 36 37 41 49
01 02 14 17 22 37
03 09 28 34 39 47
01 07 09 15 35 37
13 14 19 24 32 33
01 09 10 24 31 41
11 14 19 23 35 41
25 26 27 31 42 49
14 16 21 26 37 48
11 22 24 34 35 40
05 10 12 13 15 17
05 12 18 22 44 45
Narend,
find missing numbers range 1-49 from each row or the whole range?
See this blog post: http://www.get-digital-help.com/2009/09/20/identify-missing-numbers-in-a-range-in-excel/
Hello,
I just stumbled over this website and it's fascinating.
Still I hope you can help me with the topic above since I get a #NUM error when using the formula. I want to extrac an unique list of data sorted by their occurance. For me it seems it works only partially.
Hope you can help. Thanks
Irina,
I have pretty much changed everyting in this post. I hope it works now.
Thanks for your comment!
How can you use large with multiple criteria?? Example looking for top 5 of a list based on name, state and city..
Sara,
See this post: http://www.get-digital-help.com/2012/04/23/unique-distinct-records-sorted-by-frequency/
Hi Oscar, how do you exclude blanks from this? The formula to create the unique distinct list, sorted by occurrences from large to small is almost exactly what I'm looking for...I just can't seem to figure out where to wrap the IF(ISBLANK() to get this thing to exclude blanks.
Joe,
Array formula in cell D3:
See attached file:
unique-sorted-by-occurances-blanks.xls
Hi Oscar,
brilliant formulas here. Helped me out a lot.
Is it actually possible to sort list elements with an equal number of occurrence in alphabetical order?
Thanks in advance,
Gerald.
Gerald,
Great question!
See this file: unique-sorted-by-occurances-sorted-in-alphabetical-order.xls
Fantastic! Thanks a lot Oscar.