+ Reply to Thread
Results 1 to 5 of 5

Top 5 values using LARGE and INDEX avoiding duplicates

Hybrid View

  1. #1
    Registered User
    Join Date
    10-24-2007
    Posts
    1

    Top 5 values using LARGE and INDEX avoiding duplicates

    Hi

    I am trying to get the top 5 values in a list and return some text from an adjacent column. I have names in cells A1:A20 and some numeric value in cells B1:B20. I am looking to get the top 5 names from col A based the values in on col B.

    I have tried using LARGE, INDEX and LOOKUPs which almost work but I can not account for two cells having the same value; the end result is that one of the names gets duplicated. I found a post which comes close but I can't get it working; it uses an IF and an OFFSET to check if two values match.
    http://www.pcreview.co.uk/forums/thread-3154173.php

    I could only get the equation in the above function to return the top 5 values plus 1 (i.e. items 2,3,4,5 & 6).
    Could someone please explain or simply the above post, or provide an alternative solution?

    Regards, Carl Gilbert

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Does this example do what your after. Needs to be entered with Ctrl + Shift + enter

    VBA Noob
    Attached Files Attached Files
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Here's an alternative using a "helper" column. Using VBA Noob's setup, insert a new column A to the left of your names and use this formula in A1 copied down to give a unique rank

    =RANK(C1,C$1:C$16)+COUNTIF(C$1:C1,C1)-1

    then in G1 copied down to list the names in order

    =VLOOKUP(ROWS(G$1:G1),A$1:B$16,2,0)

  4. #4
    Registered User
    Join Date
    07-25-2012
    Location
    Brazil
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Top 5 values using LARGE and INDEX avoiding duplicates

    Thanks!


  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Top 5 values using LARGE and INDEX avoiding duplicates

    Perhaps something like this.....

    With A1:B20 containing this list:
    Alpha	100
    Bravo	90
    Charlie	20
    Delta	80
    Echo	70
    Foxtrot	120
    Golf	(blank)
    Charlie	80
    India	50
    Juliet	40
    Kilo	30
    Lima	20
    Mike	10
    November(blank)	
    Oscar	(blank)
    Papa	(blank)
    Quebec	(blank)
    Romeo	47
    Sierra	61
    Tango	45
    
    Notice:
    80 is the 4th and 5th largest value
    Charlie appears twice (at 2 and 80)


    These regular formulas returns the top_5 values in the order in which they appear in the list.
    
    This one returns the name
    C1: =INDEX($A$1:$A$20,MATCH(LARGE(INDEX($B$1:$B$20+(ROWS($B$1:$B$20)-ROW($B$1:$B$20))/10^5,0),ROWS($1:1)),INDEX($B$1:$B$20+(ROWS($B$1:$B$20)-ROW($B$1:$B$20))/10^5,0),0))
    
    This one returns the associated value
    =LARGE($B$1:$B$20,ROWS($1:1))
    
    Copy both formulas down through Row_5
    
    Using my posted example...
    These values are returned:
    Foxtrot	120
    Alpha	100
    Bravo	90
    Delta	80
    Charlie	80
    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1