Using RANK and SUMIF together?

flouee

New Member
Joined
May 25, 2011
Messages
9
Hello!

I am looking for a formula to select specific rows in a data sheet (according to a set of criterias), calculate the rank (RANK) for some of these rows (a new set of criterias), and then summarize those ranks. Is this possible and how would I do it? I was thinking about combining RANK with SUMIF but I have not been able to get it to work...

An example; I want to select all rows where column B="5", and then summarize the ranks of rows where B="5" and C="10".

(Each row of data can be in different "rank groups", so it is not possible to add an extra column for each row and calculate the rank directly in the data sheet; the rank will depend on which other rows are included in each set.)

If it helps, I need the ranks for the rows in order to do the Mann-Whitney test.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi, I appreciate Barry's helping you reach a solution to this- especially since I can usually only respond to these at night.

I'll bow out so he can work with you, but just one observation...

I'm not clear on what you mean by "calculate the sum of the ranks of each group's Tot IgG mgG-2".

You probably don't mean additive sum (2+3+1+4) = 10 ...that wouldn't be very useful.

It looks like this is what you are looking for after all. If that is the case, then I don't see how the rankings themselves affect the result.
If you have 3 items in the group the sum will be 1+2+3= 6. For 6 items it woulld be 6!=21.
The only difference is whether you are using simple ranking vs unique - then the ties would affect the result 1+2+2+2+5+6= 17.

Let me know if I missed the point, but if that is correct the formula would be greatly simplified.

Good luck! :)
 
Last edited:
Upvote 0
The point I think you are missing is that I do not want to summarize all ranks, only those belonging to the right group. First, we give all mice a rank (regardless of end score-group), then we summarize the ranks of those mice belonging to the end score=0, and separately the ones having end score=4. Thus, the total rank for both groups will be 6!, but the distribution between the two groups is what I need, in order to see if the parameter I investigate is significant different between the groups. Any clearer? :)
 
Upvote 0
Okay, it took me a bit to catch on, but now I understand. :roll:

This should work for the adjusted rankings...

Excel Workbook
ABCDEF
1MouseTot IgG mgG-2IFN-?Plack assayPCREnd score
2Mouse 2729014508450000
3Mouse 12187091002160000
4Mouse 3729024329020700004
5Mouse 365610656110800000
6Mouse 172908117015000004
7Mouse 2729000,333333333304600004
8Mouse 324304010900000
9Mouse 1218701506600000
10
11Sum of ranks for end score=022
12Sum of ranks for end score =414
Sum Ranks with Adjustment
Excel 2007
Cell Formulas
RangeFormula
E11=SUMPRODUCT(($F$2:$F$9=C11)*((RANK($B$2:$B$9,$B$2:$B$9,1))+(0.5*(COUNT($B$2:$B$9)+1-RANK($B$2:$B$9,$B$2:$B$9,0)-RANK($B$2:$B$9,$B$2:$B$9,1)))))
E12=SUMPRODUCT(($F$2:$F$9=C12)*((RANK($B$2:$B$9,$B$2:$B$9,1))+(0.5*(COUNT($B$2:$B$9)+1-RANK($B$2:$B$9,$B$2:$B$9,0)-RANK($B$2:$B$9,$B$2:$B$9,1)))))


Since you want to be able to change the criteria for different groups, I'd suggest you reference the groups from C11 and C12 so that you don't have to edit the formulas. You can just swap in the values into the formulas if you prefer.
 
Upvote 0
**** it, I just realized I forgot something that I also did not explain properly!

Your formula only work if I include all mice from the data in the rank calculation, but I only want some specific mice to be included. Better example:

<table style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; padding-left:2pt; padding-right:2pt; " border="1" cellpadding="0" cellspacing="0"> <colgroup><col style="font-weight:bold; width:30px; "><col style="width:59px;"><col style="width:94px;"><col style="width:45px;"><col style="width:66px;"></colgroup><tbody><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td> </td><td>A</td><td>B</td><td>C</td><td>D</td></tr><tr style="height:55px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">1</td><td>Mouse</td><td>Tot IgG mgG-2</td><td>Group</td><td>End score</td></tr><tr style="height:18px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">2</td><td>Mouse 2</td><td style="text-align:right; ">7290</td><td style="text-align:right; ">1</td><td style="text-align:right; ">0</td></tr><tr style="height:18px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">3</td><td>Mouse 1</td><td style="text-align:right; ">21870</td><td style="text-align:right; ">2</td><td style="text-align:right; ">0</td></tr><tr style="height:18px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">4</td><td>Mouse 3</td><td style="text-align:right; ">7290</td><td style="text-align:right; ">3</td><td style="text-align:right; ">4</td></tr><tr style="height:18px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">5</td><td>Mouse 3</td><td style="text-align:right; ">65610</td><td style="text-align:right; ">1</td><td style="text-align:right; ">0</td></tr><tr style="height:18px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">6</td><td>Mouse 1</td><td style="text-align:right; ">7290</td><td style="text-align:right; ">2</td><td style="text-align:right; ">4</td></tr><tr style="height:18px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">7</td><td>Mouse 2</td><td style="text-align:right; ">72900</td><td style="text-align:right; ">4</td><td style="text-align:right; ">4</td></tr><tr style="height:18px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">8</td><td>Mouse 2</td><td style="text-align:right; ">2324</td><td style="text-align:right; ">3
</td><td style="text-align:right; ">0</td></tr><tr style="height:18px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">9</td><td>Mouse 3</td><td style="text-align:right; ">3324</td><td style="text-align:right; ">2</td><td style="text-align:right; ">0</td></tr><tr style="height:18px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">10</td><td>Mouse 1</td><td style="text-align:right; ">323</td><td style="text-align:right; ">1</td><td style="text-align:right; ">4</td></tr><tr style="height:18px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">11</td><td>Mouse 5</td><td style="text-align:right; ">24323</td><td style="text-align:right; ">3</td><td style="text-align:right; ">4</td></tr><tr style="height:18px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">12</td><td>Mouse 3</td><td style="text-align:right; ">2430</td><td style="text-align:right; ">2</td><td style="text-align:right; ">0</td></tr><tr style="height:18px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">13</td><td>Mouse 1</td><td style="text-align:right; ">21870</td><td style="text-align:right; ">1</td><td style="text-align:right; ">0</td></tr></tbody></table>
I want to select all mice in group 1 and 3, give all of them ranks (related to only these mice, not mice in any other groups), and then summarize only those ranks belonging to the mice in group 1 or 3 with end score = 0.

Basically, I need a quite flexible formula, where I can add additional criteria for those being included in the calculations etc.. I guess that would take me back to the formula suggested by Barry, with some changes for the rank correction factor?

I am sorry for messing it up =/
 
Upvote 0
The rank formula for the first mouse should be:

=RANK(B2;$B$2:$B$9;1)+(COUNT($B$2:$B$9) + 1 - RANK(B2;$B$2:$B$9;0) - RANK(B2;$B$2:$B$9; 1))/2

Just a quick query, then. I notice that the above formula will rank so that rank 1 is applied to the lowest value....but elsewhere you have shown ranks where the highest value is 1....my suggested formula was on the assumption that the highest value would be 1.......if it's the lowest then you can just switch the > signs for <, i.e.

=SUMPRODUCT(--(F2:F9=0),COUNTIFS(F2:F9,0,B2:B9,"<"&B2:B9)+COUNTIFS(F2:F9,4,B2:B9,"<"&B2:B9)+(COUNTIFS(F2:F9,0,B2:B9,B2:B9) +COUNTIFS(F2:F9,4,B2:B9,B2:B9))/2+0.5)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,547
Members
452,925
Latest member
duyvmex

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top