+ Reply to Thread
Results 1 to 6 of 6

Find and return Top n Values

  1. #1
    Registered User
    Join Date
    11-04-2010
    Location
    Murrieta
    MS-Off Ver
    Excel 2007
    Posts
    18

    Find and return Top n Values

    I used both the Large() and Index/Match functions to find the top 5 largest and its corresponding names. The problem is when the top value are the same for two different names it repeats the name twice. See setup below:

    Name Sales
    ================
    Jim 100
    Jake 75
    Joe 100
    Jill 50
    Jason 45
    John 35

    Large function will list both 100 but Index will return Jim twice...any ideas? Thank you.
    Last edited by NBVC; 08-10-2011 at 02:22 PM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Find and return Top n Values

    Assuming your table is in A1:B7 with headers in A1:B1, and assuming you listed the largest 5 values in C2:C6, then in D2 enter:

    Please Login or Register  to view this content.
    confirmed with CTRL+SHIFT+ENTER and copy down.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Find and return Top n Values

    Checkout NBVC's post here earlier this year.

    http://www.excelforum.com/excel-work...-function.html

    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Find and return Top n Values

    Well, at least I am consistent

  5. #5
    Registered User
    Join Date
    11-04-2010
    Location
    Murrieta
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Find and return Top n Values

    Quote Originally Posted by NBVC View Post
    Assuming your table is in A1:B7 with headers in A1:B1, and assuming you listed the largest 5 values in C2:C6, then in D2 enter:

    Please Login or Register  to view this content.
    confirmed with CTRL+SHIFT+ENTER and copy down.
    THANK YOU!!!

    Could you email me an explanation? My brain starting to hurt...

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Find and return Top n Values

    =INDEX($A$2:$A$7,SMALL(IF($B$2:$B$7=C2,ROW($B$2:$B$7)-ROW($B$2)+1),COUNTIF(C$2:C2,C2)))

    is like a vlookup for multiple matches... It uses the Index() function which requires you to index the table or column to extract from and it requires the Row number to extract from which is gotten from this part: SMALL(IF($B$2:$B$7=C2,ROW($B$2:$B$7)-ROW($B$2)+1),COUNTIF(C$2:C2,C2))

    The Small() function just allows us to step up and extract one match at a time, starting from the first match found. It will extract only if a matching number to C2 is found in range $B$2:$B$7 and then it will return the corresponding row number within the range. The -ROW($B$2)+1 is added to offset the fact you didn't start at row 1...

    The last COUNTIF(C$2:C2,C2) is the k factor for the Small() function, which is like a step factor in a For...next loop in VBA. It counts the number of identical items in column C from start to point you are at to determine the "step" value

    The CSE confirmation is because it is an array formula and you have to confirm with those keys to make these formulas work.

    Then you copy down... The only thing that changes copying down is the COUNTIF(C$2:C2,C2) .. again to determine the step or next matching item.

    Hope this clarifies a bit.

+ 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