+ Reply to Thread
Results 1 to 12 of 12

Array Formula

  1. #1
    Registered User
    Join Date
    09-07-2007
    Posts
    8

    Thumbs up Array Formula

    Hi,

    I have a set of data like below:
    Key Value
    A 4
    B 2
    C 2
    D 1
    E 5
    F 5


    I'm trying to find the keys with the largest 3 values-- however, since there are multiple matches (for e.g. E/F with the same value 5), its tricky to get F to be displayed.

    I thought the following would work but it doesnt:

    * I created a column showing the 3 LARGEST values in order (Col B): =LARGE(A:A,{1,2,3} with teh following result along with a column (Col C) that shows if they are duplicates: =COUNTIF($A$1:A1,A1)
    5 1
    5 2
    4 1
    * Now I need to get the rows associated iwth that result. I thought the following formula wouldve worked. =SMALL(IF(B1:B3=B1,ROW(B1:B3),9999),C1)

    However, it does gives me a #VALUE.

    Any ideas?

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

    =INDEX($A$1:$A$6,LARGE(IF($B$1:$B$6<>"",ROW($B$1:$B$6)),ROW(A1)))

    confirmed with CTRL+SHIFT+ENTER not just ENTER... and then copied 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
    Registered User
    Join Date
    09-07-2007
    Posts
    8
    Does not work.

    Also logically:
    IF($D$41:$D$46<>"",ROW($D$41:$D$46)) will always match up to true and return the row numbers.

    LARGE(Row numbers,x) will just return the top x row numbers (rather than the row numbers with the top x values).

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

    I know there must be a better way...I have a brain freeze at the moment... but this should work.

    =INDEX($A$1:$A$6, LARGE(IF($B$1:$B$6>=LARGE($B$1:$B$6,3) ,ROW($B$1:$B$6)),ROW(A1)))

    CSE confirmed and copied down

  5. #5
    Registered User
    Join Date
    09-07-2007
    Posts
    8
    Logically that works... Just like the formula I had.

    It just outputs a #VALUE and I cant understand why.

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    If data was like this

    A 4
    B 4
    C 4
    D 1
    E 5
    F 5

    Would you want to return all "keys" except D?

  7. #7
    Registered User
    Join Date
    09-07-2007
    Posts
    8
    Well, not really. Just the top 3. So: E, F, A is the output I'm looking for.

    Basically the exact same functionality as if you did AutoFilter and went top 3.
    But as I'm sorting on multiple columns in the report, cant do autofilter (and goes without saying is that I cant use VBA).

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by daddylonglegs
    If data was like this

    A 4
    B 4
    C 4
    D 1
    E 5
    F 5

    Would you want to return all "keys" except D?

    I was thinking along the same lines....but for some reason I can't come up with the right formulation....it's Friday.......

  9. #9
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by mc24
    Logically that works... Just like the formula I had.

    It just outputs a #VALUE and I cant understand why.

    I'm getting numbers....

    Are you sure the formula, if changed, is syntactically correct?
    Attached Files Attached Files

  10. #10
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Quote Originally Posted by mc24
    Well, not really. Just the top 3. So: E, F, A is the output I'm looking for.
    OK, here's my suggestion, see attached
    Attached Files Attached Files

  11. #11
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    here's yet another using helper column that ranks the numbers first, then indexes against those rankings....
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    09-07-2007
    Posts
    8
    Thanks guys.

    One problem I kept having was that in my data-set there were a few blank rows which made the array output #N/A. Had to put another IF condition to check for that. Ugly.

+ 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