Home » excel » list – Listing top 5 items from a table in Excel

list – Listing top 5 items from a table in Excel

Posted by: admin April 23, 2020 Leave a comment

Questions:

I am trying to use the LARGE function in Excel, but when I have multiple results with the same number, it is returning the same result twice or more. What I want it to do is move on to the next item in the list. Here is an example:

=INDEX(Movies[Title],MATCH(LARGE(Movies[Rating If Genres],1),Movies[Rating If Genres],0))
=INDEX(Movies[Rating],MATCH(LARGE(Movies[Rating If Genres],1),Movies[Rating If Genres],0))

=INDEX(Movies[Title],MATCH(LARGE(Movies[Rating If Genres],2),Movies[Rating If Genres],0))
=INDEX(Movies[Rating],MATCH(LARGE(Movies[Rating If Genres],2),Movies[Rating If Genres],0))

=INDEX(Movies[Title],MATCH(LARGE(Movies[Rating If Genres],3),Movies[Rating If Genres],0))
=INDEX(Movies[Rating],MATCH(LARGE(Movies[Rating If Genres],3),Movies[Rating If Genres],0))

=INDEX(Movies[Title],MATCH(LARGE(Movies[Rating If Genres],4),Movies[Rating If Genres],0))
=INDEX(Movies[Rating],MATCH(LARGE(Movies[Rating If Genres],4),Movies[Rating If Genres],0))

=INDEX(Movies[Title],MATCH(LARGE(Movies[Rating If Genres],5),Movies[Rating If Genres],0))
=INDEX(Movies[Rating],MATCH(LARGE(Movies[Rating If Genres],5),Movies[Rating If Genres],0))

which yields:

 Title                     | Rating
 --------------------------|---------
 Alien                     | 8.5
 Blade                     | 7.0
>30 Days of Night          | 6.6
>30 Days of Night          | 6.6
 Blade: House of Chthon    | 6.5

This one shows the same movie twice (30 Days of Night), when one of them should be Blade II as it has a 6.6 rating as well.

So what I do is I store the rating in a column in the table if the genres I specify are matched in the genres of the movies (Rating If Genres). After that, I take the highest genres from that list.

How do I make it so it shows the Blade II result from the LARGE function instead of showing the 30 Days of Night twice?

How to&Answers:

In your “top 5” table, assuming that the first rating (8.5 in your example) is in B2 then try this array formula in A2

=INDEX(Movies[Title],SMALL(IF(Movies[Rating If Genres]=B2,ROW(Movies[Rating If Genres])-MIN(ROW(Movies[Rating If Genres]))+1),COUNTIF(B$2:B2,B2)))

confirmed with CTRL+SHIFT+ENTER and copied down

This will retrieve the correct titles even with repeats in the ratings

Edit: or perhaps this non-array version……

=INDEX(Movies[Title],MATCH(1,INDEX((Movies[Rating If Genres]=B2)*(COUNTIF(A$1:A1,Movies[Title])=0),0),0))

Answer:

Make a helper column for ratings.

If ratings are in column A, then formula in the first cell of the helper column (copied down)

=IF(COUNTIF($A:$A;$A5)>1;$A5+ROW($A5)*0.000001;$A5)

adds to equal rankings a tiny amount depending on their row number (i.e. always different), which will never reach the next rank. Applying LARGE to the column will rank initially equal entries.

3 times 4.8 will become 4.800002, 4.80005, 4.802, for example.

Even simpler approach: add the row number divided by a sufficiently great number to all entries: if their accuracy is 0.1, adding a tiny amount for all will make them unique. Rounding the final result will make them equal again.