+ Reply to Thread
Results 1 to 20 of 20

Rank with duplicates values not overriding the next value

  1. #1
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Rank with duplicates values not overriding the next value

    The following formula gives the rank for different subjects of a class.
    =COUNTIFS(Subjects,C3,Marks,">"&D3)+1
    However if 2 students score the same marks in say English subject, then the next Rank is calculated as 4. What I want is to modify this in a manner that the next Rank calculated be 3 instead of 4 and so on.

    So the following table shows the values of RANK that I want generated.

    --------------------------------------
    Roll No | Subject | Marks | RANK |
    --------------------------------------
    -- 1 -- | English | ---80--| ---1---|
    -- 2 -- | English | ---78--| ---2---|
    -- 3 -- | English | ---78--| ---2---|
    -- 4 -- | English | ---76--| ---3---|
    -- 5 -- | English | ---75--| ---4---|
    -- 6 -- | English | ---72--| ---5---|
    ..
    ..

    -- 1 -- | Biology | ---92--| ---1---|
    -- 2 -- | Biology | ---92--| ---1---|
    -- 3 -- | Biology | ---90--| ---2---|
    -- 4 -- | Biology | ---88--| ---3---|
    -- 5 -- | Biology | ---88--| ---3---|
    -- 6 -- | Biology | ---85--| ---4---|

    Any help on this is appreciated. Thanks !

  2. #2
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: Rank with duplicates values not overriding the next value

    A
    B
    C
    D
    2
    1
    Eng
    80
    1
    3
    2
    Eng
    78
    2
    4
    3
    Eng
    78
    2
    5
    4
    Eng
    76
    3
    6
    5
    Eng
    75
    4
    7
    6
    Eng
    72
    5
    8
    9
    1
    Bio
    92
    1
    10
    2
    Bio
    92
    1
    11
    3
    Bio
    90
    2
    12
    4
    Bio
    88
    3
    13
    5
    Bio
    88
    3
    14
    6
    Bio
    85
    4



    A
    B
    C
    D
    2
    1
    Eng
    80
    =IF(C2<>C1,D1+1,D1)
    3
    2
    Eng
    78
    =IF(C3<>C2,D2+1,D2)
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  3. #3
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Rank with duplicates values not overriding the next value

    Another way compliments of the late Chip Pearson here:


    A
    B
    C
    D
    E
    F
    1
    Roll No
    Subject
    Marks
    RANK
    By formula
    2
    1
    English
    80
    1
    1
    =RANK(C2,$C$2:$C$7)+COUNTIF(C$2:C2,C2)-1
    3
    2
    English
    78
    2
    2
    4
    3
    English
    78
    2
    3
    5
    4
    English
    76
    3
    4
    6
    5
    English
    75
    4
    5
    7
    6
    English
    72
    5
    6
    8
    ..
    9
    ..
    10
    11
    1
    Biology
    92
    1
    1
    =RANK(C11,$C$11:$C$16)+COUNTIF($D$11:D11,D11)-1
    12
    2
    Biology
    92
    1
    2
    13
    3
    Biology
    90
    2
    3
    14
    4
    Biology
    88
    3
    4
    15
    5
    Biology
    88
    3
    5
    16
    6
    Biology
    85
    4
    6
    Dave

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,704

    Re: Rank with duplicates values not overriding the next value

    @Ajoo,

    the problem with your desired ranking is that it looks like student 6 came 5th in the class in English, and 4th in the class in Biology.

    Pete

  5. #5
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: Rank with duplicates values not overriding the next value

    Hi all !

    Thanks for the answer and the insights.

    @Kokosec : If the list is large and contiguous with no separation between the subjects ( unlike as shown in the table by me ), the formula fails at the change of subject. I would want to write the formula and pull it down across hundreds of rows and it should work across subject boundries.

    @FlameRetired : That's not how I would want my result as shown by the yellow columns. I have showed the result I want in my table. Or am i missing / overlooking something in my answer.

    the problem with your desired ranking is that it looks like student 6 came 5th in the class in English, and 4th in the class in Biology.
    @Pete : I am not sure I understand what the problem is. If we go by the marks, then those are the ranks of student 6 as they should be.

    Kokosec's reply seems to accomplish what I want but fails at the subject boundries. Any help in improving that would be great !

    Thanks again to all of you!

  6. #6
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,824

    Re: Rank with duplicates values not overriding the next value

    If Kokosec's works for you except when change subjects and no spaces, you can try this:
    =IF(B2<>B1,1,IF(C2<>C1,D1+1,D1))

  7. #7
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,577

    Re: Rank with duplicates values not overriding the next value

    Pl see file.
    In D2 ARRAY formula
    Please Login or Register  to view this content.
    Copy down.

    How ARRAY formula is entered

    Paste Formula in the cell.
    Press F2
    Hold Shift+ Ctrl Keys and hit Enter key.
    Now the formula is surrounded by {} by excel.
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  8. #8
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,899

    Re: Rank with duplicates values not overriding the next value

    Or try:

    =SUMPRODUCT(($B$2:$B$20=B2)*($C$2:$C$20>C2)/COUNTIFS($B$2:$B$20,$B$2:$B$20,$C$2:$C$20,$C$2:$C$20))+1

  9. #9
    Forum Expert
    Join Date
    09-30-2019
    Location
    Chiangmai, Thailand
    MS-Off Ver
    Office 2016, Excel 2019
    Posts
    1,234

    Re: Rank with duplicates values not overriding the next value

    I can only do with a helper column.

    Helper column
    F2
    Please Login or Register  to view this content.
    Ranking D2
    Please Login or Register  to view this content.

    Regards.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: Rank with duplicates values not overriding the next value

    Hi,

    Grateful to receive so many replies !

    @Gregb11: This does not seem to work. I tried with a lot of variations but could not get it working.

    @kvsrinivasamurthy : Your formula is, I guess, only for one subject and works great there. However my problem is slightly more general and I needed it for all the subjects.

    @menem : I cannot download your file. I tried thrice but each time i go to a page which says you are not logged in.

    @Phuocam : Your formula works just great !! Thanks !! However, there is one more small issue that I would like to request modification for. What if there are some students absent and their result shows "A", then how can that be incorporated in your formula to give the correct result.

    Thanks !

  11. #11
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,824

    Re: Rank with duplicates values not overriding the next value

    This formula works for me.

    =IF(B2="","",IF(B2<>B1,1,IF(C2<>C1,D1+1,D1)))

    I've uploaded a file that shows it working. Again, this was assuming that Kokosec's formula worked as you stated, meaning that the list would be sorted by Subject and then by Mark/Grade.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: Rank with duplicates values not overriding the next value

    Hi Gregb11,

    Thanks for the reply. Your formula works fine as demonstrated by your file. However the problem that I am trying to solve is slightly different. Just to clarify so that there is no confusion, I will post the modified table again as below:

    -----------------------------------
    Roll No | Subject | Marks | -RANK- |
    -----------------------------------
    -- 1 -- | English | ---A---| -------|
    -- 2 -- | English | ---78--| ---1---|
    -- 3 -- | English | ---76--| ---2---|
    -- 4 -- | English | ---76--| ---2---|
    -- 5 -- | English | ---75--| ---3---|
    -- 6 -- | English | ---72--| ---4---|
    -- 7 -- | Biology | ---92--| ---1---|
    -- 8 -- | Biology | ---92--| ---1---|
    -- 9 -- | Biology | ---90--| ---2---|
    -- 10- | Biology | ---88-- | ---3---|
    -- 11- | Biology | ---88-- | ---3---|
    -- 12- | Biology | ---85-- | ---4---|
    -- 13- |Physics | ---A-- | -------|
    -- 14- |Physics | ---A-- | -------|
    -- 15- |Physics | ---90---| ---1---|
    -- 16- |Physics | ---85---| ---2---|
    -- 17- |Physics | ---83---| ---3---|
    -- 18- |Physics | ---83---| ---3---|
    -- 19- |Physics | ---81---| ---4---|
    -- 20- |Physics | ---80---| ---5---|
    -- 21- |Physics | ---80---| ---5---|
    -- 22- |Physics | ---78---| ---6---|
    -- 23- |Physics | ---75---| ---7---|
    .
    .

    In your formula, you are checking for the subject as blank (if B2 = ""), which is not required. What is required to be checked is that if the student was active and has an "A" in the marks column, instead of marks. So ( if C2 = "A") ... , Then the logic is to be devised accordingly.

    I hope that I have described the problem adequately.
    Thanks loads.
    Last edited by Ajoo; 11-16-2019 at 02:20 PM.

  13. #13
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,824

    Re: Rank with duplicates values not overriding the next value

    This is one of the problems when you paste in data as opposed to uploading a file. In your first post, you had rows where there were spaces. Now you don't. And now you've introduced an "A" under Marks where there were none before. What does the "A" mean, that they got a grade of A (91 - 100) or they are active? If column C = "A", then what do you want done - just bypass it? Can it be anything else than an "A" or a number - can it be "B", "C", etc.? You need to attach an actual Excel file and demonstrate clearly what you are looking for and what the problem is.

  14. #14
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: Rank with duplicates values not overriding the next value

    Hi Gregb11,

    Thanks for the response. The "A" stands for Absent and will be nothing else, like B or C. So only A or numeric values in the Marks column.
    In the earlier table , the spaces and .. between subjects was simply meant to depict more such data in the table. The exact table as is I have pasted in my immediately previous reply. Only there can be more subjects and so more such rows. Since the table runs into 100's of lines I thought it best to keep it small and limited.

    So please consider the table referred to above as the actual data table. Thanks !

  15. #15
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,899

    Re: Rank with duplicates values not overriding the next value

    Quote Originally Posted by Ajoo View Post
    What if there are some students absent and their result shows "A",
    then how can that be incorporated in your formula to give the correct result.
    Edit the formula:

    =IF(ISNUMBER(C2),SUM(IF(($B$2:$B$20=B2)*($C$2:$C$20>C2)*ISNUMBER($C$2:$C$20),
    1/COUNTIFS($B$2:$B$20,B2,$C$2:$C$20,$C$2:$C$20)))+1,"")

    Enter with Ctrl+Shift+ Enter.

  16. #16
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: Rank with duplicates values not overriding the next value

    Hi !

    @Phuocam : Thanks ! worked perfectly !! I really wish you can give some explanation of the working of this wonderful expression. I have no clue how this logic works, even though i have tried to wrack my brains a bit over it.

    @Gregb11: I think your solution is the simplest if this last bit can be incorporated. I would very much love to see if you can do this by modifying the simple formula that you have applied.

    Thanks all for the incredible response !!!

    Regards

  17. #17
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,824

    Re: Rank with duplicates values not overriding the next value

    In D2, try:
    =IF(C2="A","",IF(C1="A",1,IF(B2<>B1,1,IF(C2<>C1,D1+1,D1))))

    Again, this assumes that all the subjects will be sorted, and then sorted by Marks with the "A"s at the top. If these assumptions aren't true, then this formula will not work.

  18. #18
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: Rank with duplicates values not overriding the next value

    Hi Gregb11,

    Thanks for the reply and the new formula. I tried it on the same data that I put here but it seems to fail. Please find attached the file in case I have done something wrong or missed something.
    Thanks again.
    Attached Files Attached Files

  19. #19
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,824

    Re: Rank with duplicates values not overriding the next value

    In COL C, your "A"s were not "A", the first one had a space after it, and the others had a couple of spaces after the A and also a space before the "A". When all spaces were removed, it seems to be working correctly.
    If you're going to have spaces around the "A", I added "Trim" to the formula to take care of that. It's:
    =IF(TRIM(C2)="A","",IF(TRIM(C1)="A",1,IF(B2<>B1,1,IF(C2<>C1,D1+1,D1))))
    I've attache the file for your reference.
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    08-29-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    26

    Re: Rank with duplicates values not overriding the next value

    Hi Gregb11,

    It's working perfectly. I am sorry that there were spaces around the "A" which were causing it to fail. Trim is a good idea. Thanks loads !

    Thanks again to all for their replies and support.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Formula to eliminate duplicates in Rank values in a dynamic range
    By bungaree in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 08-14-2016, 08:23 PM
  2. Ranking values and ranking duplicates the same rank
    By 302arpks in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 03-05-2015, 01:50 PM
  3. [SOLVED] Rank values in descending order with duplicates
    By mcain1981 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-14-2012, 01:15 PM
  4. [SOLVED] RANK formula cannot rank duplicates
    By unpluggedmusic in forum Excel General
    Replies: 5
    Last Post: 10-13-2012, 12:59 PM
  5. Weighted rank- if duplicates rank the average
    By vlady in forum Excel General
    Replies: 3
    Last Post: 02-28-2012, 09:17 PM
  6. Replies: 6
    Last Post: 06-01-2010, 06:19 PM
  7. Excel Rank Duplicates then preferred rank
    By Economic in forum Excel General
    Replies: 2
    Last Post: 04-05-2009, 07:45 PM

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