Closed Thread
Results 1 to 7 of 7

ranking within group

  1. #1
    Registered User
    Join Date
    06-22-2005
    Location
    Washington, USA
    MS-Off Ver
    Office 365
    Posts
    40

    ranking within group

    Hi,

    I have the following groups and values

    a 5
    b 6
    c 7
    a 35
    a 36
    c 32
    c 9
    b 8

    What I'd like to do is rank each value but within its own group (rank all the As together, B's together, and C's together).

    any ideas?

    I wish there was a rankif(), but no such luck.

    thanks!

    -joel

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Assuming your data is in A1:B8 and you want to rank the highest number within each category as 1 then try this formula in C1 copied down

    =SUMPRODUCT(($A$1:$A$8=A1)*($B$1:$B$8>B1))+1

  3. #3
    Registered User
    Join Date
    06-22-2005
    Location
    Washington, USA
    MS-Off Ver
    Office 365
    Posts
    40
    Quote Originally Posted by daddylonglegs
    Assuming your data is in A1:B8 and you want to rank the highest number within each category as 1 then try this formula in C1 copied down

    =SUMPRODUCT(($A$1:$A$8=A1)*($B$1:$B$8>B1))+1
    this is awesome. Can you explain why this works? I understand how the basic sumproduct works, but I'm not understanding why it does the count when you have the =a1 and the >b1.

    thanks for your help!

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    It's probably easiest to understand when you know that RANK function can be replicated by COUNTIF, so for a straight RANK of numbers in B1:B8 you can use this formula.

    =COUNTIF(B$1:B$8,B1)+1

    This works because the rank of a number is the same as the count of numbers within the range greater than that number.....plus 1

    Now you want to add another condition so that you are only ranking for each specific category in column A. To add another condition you need to switch to SUMPRODUCT (or you can use COUNTIFS function in Excel 2007).

    The SUMPRODUCT function gives a count of numbers greater than that to be ranked (>A1)....but also within the category (=B1) then adds 1 (otherwise the top rank would be zero).

    Note that just like the RANK function, if two numbers are tied at 1 then there will be no rank 2, next rank will be 3.

  5. #5
    Registered User
    Join Date
    06-22-2005
    Location
    Washington, USA
    MS-Off Ver
    Office 365
    Posts
    40
    thanks for the help and the explanation.

    question, it appears as though there is a limit to how many rows you can use. I tried 1,000 and no luck.

    any idea how to get around that? I'm looking at 26000+ records. :D

    -joel

  6. #6
    Forum Contributor tangcla's Avatar
    Join Date
    06-04-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2010
    Posts
    136
    Quote Originally Posted by jojotherider
    question, it appears as though there is a limit to how many rows you can use. I tried 1,000 and no luck.
    Bump for an awesome thread, I think this answered my question, along with this link has solved my problems!

    But would also like to know if there's a limit in rankings. I only need about 700 though (no need for a monster like 26K)
    Last edited by tangcla; 06-12-2008 at 08:32 PM.

  7. #7
    Forum Contributor
    Join Date
    07-18-2006
    Posts
    135
    Dear all,

    pls help me this issue about rank by group,

    Thanks in advance,
    Attached Files Attached Files
    Last edited by vumian; 12-09-2008 at 12:47 PM.

Closed 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