Tie breaking using Rank function - excel

I have a student's result sheet, where I calculated the total number the student has gained. Next, I want to rank them according to the grand total, and wherever it duplicates, the student getting more number in maths(E9:E58) will be given priority,
How to accomplish it?
I have my grand total from U9 to U58, and maths score in d9 to d58.
I have used this formula:
=Rank(u9,u9:u58,1)
I am stuck in how to use the if condition within the rank function.
Please help.
Thanks in advance....

In that sort of situation, one method of adjusting is to use the SUMPRODUCT function. You will need to adapt my example to your data ranges. In the example below, you don't need columns E:F. They are only there so you can better see how the adjustment is accomplished.
Adjustment Function:
=SUMPRODUCT((C2=Totals)*(B2>Maths))
adj Rank Function
D2: =RANK(C2,Totals,1)+SUMPRODUCT((C2=Totals)*(B2>Maths))

Assuming, Total score is in Column U and Math's score is in Column E, you can use Ron's solution as:
=RANK(U9,U$9:U$58)+SUMPRODUCT((U$9:U$58=U9)*(E$9:E$58<E9))
Enter above formula in 9th row of the column where you want Rank to be displayed and then drag/copy it down till 58th row.

This is more of arithmetic approach. I would add a column called adjusted total.
AdjTotal = Total + (Maths Score / Max possible Maths Score) * 0.9
Then use this Adjusted score column to rank.
The adjustment will add a fraction under 1 to the total and will help break the tie when there is one. Since the adjustment will never be more than 0.9 it will not affect ranks when there is no tie.
Assuming Max score for Maths is 100, use this
V9 = U9 + D9/100*0.9
Copy V2 down till V59
W9 = RANK(V9, V$9:V$59, 1)
Copy W9 down.

You can do this by running the usual RANK() method and then adding in the RANK() method on a filtered set that matches the other rows tied with the current row. Since the RANK() call for the tiebreak will start at one you will need to subtract one to compensate.
The end result ends up looking like:
=RANK(U9, U$9:U$58, 1) + RANK(D9, FILTER(D$9:D$58, U$9:U$58=U9)) - 1

Related

INDEX & MATCH in excel

I have this table in excel
I want to create a new column where if have a total score let's say of 92 I do an index/match on the table and get it.
I tried this
=INDEX('Risk Assessment Matrix '!I24:I28,1,1,MATCH(111,'Risk Assessment Matrix '!J24:J28,0))
but not working.
Any help please?
Thanks,
Ilias
Assuming a value given is not above 140, you don't even need a 3rd column. Try:
Formula in D2:
=INDEX(A1:A5,MATCH(D1,B1:B5,-1))
If D1 happens to be above 140 an error is returned. You can catch that by nesting the above in =IFERROR(<TheAbove>,"No Match") for example.
Reorder the list so the third column is ascending not descending. and change the >=0 to just 0
Then use:
=INDEX('Risk Assessment Matrix '!I24:I28,MATCH(111,'Risk Assessment Matrix '!K24:K28))
Your INDEX/MATCH looks a bit odd. You wouldn't normally have the "1,1," in there.
Try this:
=INDEX('Risk Assessment Matrix '!I24:I28, MATCH(111,'Risk Assessment Matrix '!J24:J28,0))
This should return "High" (assuming your first column in the table is "I".
Two methods shown:
Pay attention to the order.
An alternate option is the use the new XLOOKUP function.
Although it would require changing the minimum value range from 0 to -9999. An out of range value for non-numeric values of 9999 would also need to be added.
It has the advantage of being easier to read compared to INDEX and MATCH.
=XLOOKUP($D2,$B$2:$B$6,$A$2:$A$6,"Not Found",-1)
The formula looks up the value against a single list of minimum values.
The match_mode (last parameter) is set to -1. This means perform an exact match and if nothing is found return the next smaller item.

Excel Calculate a running average on filtered data with criteria

I am trying to calculate a running average on a filtered data table. All other posts online use Sumproduct(Subtotal) on the entire range but do not calculate a row by row running average
I am stuck on how to calculate columns C and D.
If column B (Score) > 0, I want to sum and average it under column C (Average Win)
If column B (Score) < 0, I want to sum and average it under column D (Average Loss)
The table is filterable by column A (Type) and the results should look as follows
Progress so far:
I have figured out how to calculate a Cumulative score based on filtered data. However this does not fully solve my problem. I appreciate any help!
=SUBTOTAL(3,B3)*SUBTOTAL(9,B$3:B3)
SUBTOTAL(3,B3) checks if the current row is visible, SUBTOTAL(9,B$3:b3) sums the values.
Final update needed
Jos - Thank you for your detailed explanation on how subtotal() works. I learned a ton through your explanation and will continue to study it. This is my first time being exposed to structured referencing so some of the syntax is a bit confusing to me still
The last formula I need is a running win % column where a Win is defined by score > 0. Please see the picture below
My assumptions believe that the same formula would work, except that we average a 1 or 0 in each row instead of the [Score] column.
Using the prior solution, why can't we modify the output of your prior solution to calculate a running win %?
[...] IF([Score]>0,IF(ROW([Score])<=ROW([#Score]),[Win])))),0)
Where [Win] is a helper column with the outputs 1 for win, 0 for loss.
This could be done by saying
if([#score]>0,1,0)
Instead of averaging out the actual #Score, this would average out a column of 1's and 0's with the desired output 0%, 50%, 66%, etc.
I am aware that the solution I provided does not work but I am trying to embrace the correct logic. I still struggle to understand how these structured column references are calculated on a row by row basis.
For example: Average(If([Score]>0,[Score])
How is this calculated on a row by row basis? When A3 does If([Score] > 0,), does this equal If({-10}>0)? When on A4, does If([Score]>0) equal If({-10,20} >0)? Thank you for your patience and help thus far.
I disagree with your result for Average Loss for the last row of your unfiltered table (surely -9.33...?), but try this for Average Win:
=IFERROR(AVERAGE(IF(SUBTOTAL(3,OFFSET(INDEX([Score],1),ROW([Score])-MIN(ROW([Score])),)),IF([Score]>0,IF(ROW([Score])<=ROW([#Score]),[Score])))),0)
Same formula for Average Loss, changing [Score]>0 to [Score]<0.
Explanation:
Using the data you provided and assuming:
The table's top-left cell is in A1
The table is filtered on the Type column for "A"
In order to determine which rows are filtered, we must pass an array of range references - i.e. for each cell within a chosen column of the table - to the SUBTOTAL function. It's a touch unfortunate that such an array of range references can only be generated via a volatile function (INDIRECT or OFFSET), but here, unless we resort to helper columns, we are left with no choice.
INDEX([Score],1)
simply returns a range reference to the first cell within the Score column. When using Excel tables, it's preferable not to write formulas which include a mixture of structured and non-structured referencing, even if that results in slightly longer expressions. So here, for example, we would not reference A2 within the formula.
ROW([Score])-MIN(ROW([Score]))
generates an array of integers from 0 up to one fewer than the number of rows in the table, i.e.
{0;1;2;3;4}
and so
=IFERROR(AVERAGE(IF(SUBTOTAL(3,OFFSET(INDEX([Score],1),ROW([Score])-MIN(ROW([Score])),)),IF([Score]>0,IF(ROW([Score])<=ROW([#Score]),[Score])))),0)
becomes
=IFERROR(AVERAGE(IF(SUBTOTAL(3,OFFSET(A2,{0;1;2;3;4},)),IF([Score]>0,IF(ROW([Score])<=ROW([#Score]),[Score])))),0)
OFFSET then generates an array of range references (though note that you will not be able to 'see' this step within the Evaluate Formula window - rather, an array of #VALUE! errors is displayed):
=IFERROR(AVERAGE(IF(SUBTOTAL(3,{A2;A3;A4;A5;A6}),IF([Score]>0,IF(ROW([Score])<=ROW([#Score]),[Score])))),0)
SUBTOTAL then determines which of these range references is filtered (note that care must be given here to the choice of first parameter), returning the relevant Boolean, so that:
SUBTOTAL(3,{A2;A3;A4;A5;A6})
resolves to:
{1;1;1;0;1}
And so we now have:
=IFERROR(AVERAGE(IF({1;1;1;0;1},IF([Score]>0,IF(ROW([Score])<=ROW([#Score]),[Score])))),0)
and the rest is straightforward.
So, I would use averageifs().
=averageifs(B:B,B:B,">=1",A:A,"A")
is one example, note I have added the control of Type A in the example.
See:

Calculations based on index/offset that incorporates multiple columns in one function

Here is an example spreadsheet:
The idea is that one has a monte carlo simulation of Bitcoin prices starting from column G. I then calculate the rank of the terminal values (row 7, columns H:L), 1 being the highest price. Based on the rank value set in cell E1, I want to calculate the average price of the bitcoin. So if rank is 3, then I want to take paths that correspond to ranks 3,4,5 -> i.e. column H,I and L. And then I want the values in B2 to = average(H2,I2,L2), in B3 = average(H3,I3,L3), etc.
I couldn't make this work with offsets. Because depending on the E1 value, you will have a variable number of columns that you want to average. Obviously, I have many more columns in my main spreadsheet. Currently 9000 columns. I would do this in Python, but I have to stick to Excel. How would I achieve my goal?
Thanks
EDIT: It does not have to be index/offset. But I just thought that those are probably the function that will help in this case. Rank can be obtained with the =RANK() function.
If I understand your question correctly, it sounds like you need AVERAGEIF, e.g. in cell B2:
= AVERAGEIF($H$8:$L$8,">="&$E$1,$H2:$L2)
(And then drag this formula down to cell B6.)
EDIT
To use more than one condition, you have to use AVERAGEIFS instead of AVERAGEIF.
E.g., something like this:
= AVERAGEIFS($H2:$L2,$H$8:$L$8,">="&$E$1,$H$8:$L$8,"<="& <whatever> )

Using VLOOKUP to return information based on the maximum value in a range

I am trying to use vlookup to return information based on the maximum value of a cell within a range.
I have a table in which each row is a sports team and each column is a weekly points total.
I have 2 cells that show the highest points scored in the current week and the name of the team that scored them.
The team name is generated by the formula
=VLOOKUP(MAX(Admin!G3:G16),Admin!G3:K16, 5, FALSE)
This works fine.
I also wish to have 2 cells that show the highest weekly points total ever achieved, along with the name of the relevant team.
However, I can not amend the above formula to work on a range instead of a row, and no matter what I do, it always returns an #N/A result for the team name.
The most logical formula I tried is
=VLOOKUP(MAX(Admin!N18:BE31),Admin!N18:BG31, 47, FALSE)
where columns N through BE are the weekly scores (which are generated by a formula, if that makes a difference?) and column BG contains the team names.
Maybe this function isn't designed to work on a range in the same way as a column, maybe I have made an error in the formula, or maybe there is another better way to retrieve the information?
I just can't work it out, so am sincerely hoping somebody can point me in the right direction.
Many thanks for any assistance.
Indeed, the vlookup function works only with columns. So does the match function. You need here to use a formula array (hit "Ctrl + Shift + Enter" once you've typed the function instead of the usual "Enter").
I came to the following function
=INDEX($A$2:$A$9,SMALL(IF($B$2:$D$9=$H$2,MATCH($A$2:$A$9,$A$2:$A$9,0),""),1))
with :
1) $A$2:$A$9 = The teams
2) $B$2:$D$9 = The weekly scores
3) $H$2 = the maximal score ever achieved
You just need to adapt the ranges and hit "Ctrl + Shift + Enter"
PS: If 2 teams achieved this score, then only the first one will show

Excel: AVERAGE IF

Lets say I have an Excel sheet such that:
Column 1 contains salaries
Column 2 contains gender (M/F)
How can I calculate the average salary for females?
=AVERAGE(IF(B1:B10="F",A1:A10))
entered as an array function (ie using Shift-CTRL-Enter rather than just Enter)
Allthough the answer is already answered/accepted I can't resist to add my 2 cents:
Sums and averages normally are displayed at the bottom of a list. You can use the SUBTOTAL() function to calculate sum and average and specify to include or exclude "hidden" values, i.e. values suppressed by a filter. So the solution could be:
create a formula =SUBTOTAL(101,A2:A6) for the average
create a formula =SUBTOTAL(109,A2:A6) for the sum
create an autofilter on the Gender column
Now, when you filter for "F", "M" or all, the correct sum and average will always be computed.
Hope that helps - Good luck
To do it without an array formula just use this:
=SUMIF(B:B,"F",A:A)/COUNTIF(B:B,"F")
Answered question, solid formulas - BUT - beware of conditional averages based on numbers:
In a very similar situation I tried:
"=AVERAGE(IF(F696:F824<0;E696:E824))" (shift control enter) - In English this asked Excel to calculate an average on all numbers in column E if a result in column F was negative (a loss) - e.g. "calculate an average for all items where a loss occured". (no circular reference)
When asked to calculate an average for all items where a gain (x>0) occured, Excel got it right. However, when the conditional average was based on a loss - Excel produced a huge error (7.53 instead of 28.27).
I then opened exactly the same document in Open Office, where Calc got the (correct) answer 28,27 from the same Array formula.
Recalculating the whole thing in steps in Excel (first new column of only losses, new for only gains, new column for only E-values where a loss/gain occured, then a "clean" (unconditional) average calculation, produced the correct values.
Thus, it should be noted that Excel and Open Office produce different answers (and Excel 2007, Swedish language version, gets them wrong) in some cases of conditional averages.
(sorry for my long cautionary tale - but be a bit careful when the condition is a number would be my advice)
You can put filter in top line of your sheet. Then Filter only Fs from Column2, then calculate average of values.
Or you can add additional column with female salaries only.
The formula would be like: =IF(B1 = "Female";A1)
Then you simply calculate average of newly created column.
Salaries gender
2500 M 0 2500*0
2400 F 1 2400×1
2300 F 1 2300×1
sum =2 sum=4700 average=4700/2
Maybe it be complex.

Resources