+ Reply to Thread
Results 1 to 6 of 6

Search for SECOND highest number in an array

  1. #1
    Registered User
    Join Date
    05-24-2009
    Location
    Sydney, Asutralia
    MS-Off Ver
    Windows 7 Professional, Office 2010 (Word, Excel, PowerPoint, etc)
    Posts
    6

    Search for SECOND highest number in an array

    Hi All,

    I am trying to find the second highest number in an array and then use a lookup function to let me know in which year the second highest number occurred. My data is per below:

    Dec-02 0
    Dec-03 144
    Dec-04 100
    Dec-05 415
    Dec-06 307
    Dec-07 276
    Dec-08 197
    Dec-09 186
    Dec-10 354
    Dec-11 275
    Dec-12 552

    Using this formula =TEXT(LOOKUP(LARGE(B1:B11,2),B1:B11,A1:A11),"yyyy") I get the result "2011" when it clearly should be "2005"...

    I am using this formula elsewhere in the spreadsheet and it works just fine.

    Any help would be greatly appreciated.

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Search for SECOND highest number in an array

    for lookup to work properly the values in col b need to be in ascending order
    try
    =TEXT(INDEX(A1:A11,MATCH(LARGE(B1:B11,2),B1:B11,0)),"yyyy")
    or
    =TEXT(VLOOKUP(LARGE(B1:B11,2),CHOOSE({1,2},B1:B11,A1:A11),2,0),"yyyy")
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Search for SECOND highest number in an array

    You need the range to be sorted ascending for LOOKUP to work.

    Try this.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  4. #4
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Search for SECOND highest number in an array

    Here's another one:

    =YEAR(INDEX(A1:A11,MATCH(LARGE(B1:B11,2),B1:B11,0)))
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  5. #5
    Registered User
    Join Date
    05-24-2009
    Location
    Sydney, Asutralia
    MS-Off Ver
    Windows 7 Professional, Office 2010 (Word, Excel, PowerPoint, etc)
    Posts
    6

    Re: Search for SECOND highest number in an array

    Thanks Martin, Norie and Tony. All three worked perefctly.

    Regards.

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Search for SECOND highest number in an array

    You're welcome. We appreciate the feedback!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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