I'm working on a King of the Hill/Elimination bracket spreadsheet & I have a cell that I want to return the cut (last score in the top 50%). Would anyone know how to go about this?
I have a formula for the average of the range, excluding 0's, but that isnt accurate since it isnt actually showing the lowest score. =AVERAGEIF(F9:G667,"<>0")
What you're describing is "percentile". Excel's percentile function interpolates, so I'm not sure it's appropriate for your use case.
See https://support.office.com/en-us/article/percentile-function-91b43a53-543c-4708-93de-d626debdddca
At the very least, you can compute the percentile, then take the minimum score of all values filtered to be above the interpolated 50th percentile.
Here's a slightly clever implementation:
Assume your data is in the range C2:C11.
In c13, we'll compute the 50th percentile as =PERCENTILE(C2:C11, 0.5)
In column d, we'll use an IF statement to either select the adjacent value from column c, or a very large number, depending on whether the value is greater than the percentile. E.g., =IF(C2 > $C$13,C2,400000)
Now we can take the min of column d: =MIN(D2:D11)
The only clever bit is using a giant number when the value in column c is less than the percentile, so that it effectively becomes invisible to the min operation.
The last score in the top 50% is the kth largest item where k is the number of items divided by 2. Excel has a useful function called LARGE, which returns the kth largest item. It also have an even more useful function called AGGREGATE which lets you do things like SUM, COUNT, AVERAGE, LARGE, SMALL, etc - but skips hidden rows or Error Values.
So, to get the kth item of the list (ignoring Error Values) we would use =AGGREGATE(15, 6, F9:G667, k) - of course, this is not going to skip 0, because 0 is not an error. But, you know what is? Divide by 0. So, if we do F9*F9/F9, then we will either get F9 (for F9<>0) or the #DIV/0! error.
This now means our function is =AGGREGATE(15, 6, F9:G667*F9:G667/F9:G667, k), but we still need to decide on a value for k. Well, if we have 3 items then we want the 2nd one, if we have 6 items then we want the 6rd one - so, for n items we want item n÷2, rounded up. Well, that's what the ROUNDUP function is for!
Still, we need to know what n is - but that's simple. It's just the number of non-0 items in the list, or COUNTIF(F9:G667,"<>0") (Or ">0" if your list cannot contain negative numbers)
Plug it all together, and we get this:
=AGGREGATE(15, 6, F9:G667*F9:G667/F9:G667, ROUNDUP(COUNTIF(F9:G667,"<>0"), 0))
Related
I have a column that may contain X number of values. I am looking to get the average of the top Y values, based on the number of X values that are above 0. There are just two rules on how to come to this value.
Y must represent 49% or less of the values greater than 0. If I have 11 total values that are above 0, then I can only take the top 5.39 values that I can take an average on.
Y must be a whole number and rounded down. To take the last piece of criteria further, 5.39 would round down to 5, so I am essentially getting the average of the top 5 values.
I feel like I am getting close with different solutions but have struggled. For instance, the solution at Getting average of top 30% of the values in one column is close, however, it appears to find the values above the 0.7 number, and not necessary the top 30%.
Here is my data,
92.593
88.889
45.679
88.889
0
88.889
87.654
0
69.136
41.975
49.383
0
40.741
50.617
0
Here I have 11 values that are above 0. I know that using the criteria I mentioned above, I can only average the top 5 values. Those top 5 values average out to be 89.383.
I have tried something like this,
=AVERAGE(LARGE(A1:A14), ROW($B$1:$B2)))
Where B1 just has the value 1, and B2 has a formula that calculates the number of values I can have, with no such luck.
I don't know your XL version, but this also works with older versions
=AVERAGE(LARGE(IF(A1:A15>0,A1:A15),ROW(INDIRECT(B1&":"&B2))))
remember to confirm as array formula using CTRL+SHIFT+ENTER
I hope that's what you are looking for,
bye.
I have two Excel lists:
One extensive with 20 thousand lines. In which:
Two columns are important: First: Unique ID, Second: a value (number formatted).
It can be a value that appears several times, or only once.
I have to create the second list. In this list I have only one column of values that I would like to have.
I need a formula that will look for values from List 2 in List 1 and then match a Unique ID to each value.
It is important that, when no direct value exist. In this case it has to search for a sample which is in about 3-5% value deviation.
Example: there was no value 127, but within 3%, 125 was found.
I've tried indexing and comparison, but it does not seem to work.
VLOOKUP worked, but without 3-5% deviation
I am very grateful for the help.
Example: http://www.filedropper.com/excellist1and2
If the value exists in the list, you can use VLOOKUP or INDEX(MATCH to find it - that's the easy part. If the value is not in the list, then you need to find the nearest value.
The nearest "low" value will be the MAX value ≤ our input, and the nearest "high" value will be the MIN value ≥ our input.
If you have Office 365, you can use MINIFS($D$1:$D$6,$D$1:$D$6,">="&B1,$D$1:$D$6,"<="&(B1*1.05)) and MAXIFS($D$1:$D$6,$D$1:$D$6,"<="&B1,$D$1:$D$6,">="&(B1*0.95)) )` here. If not, you'll need an Array Formula, we can build that "±5%" in early, to simplify the formula.
Starting with the Low values, we want the MAX value ≤ our input and ≥ 95% of our input. Putting an Array Formula in a SUMPRODUCT so that we can use it in a normal formula, we get =SUMPRODUCT(MAX($D$1:$D$6*--($D$1:$D$6<=B1)*--($D$1:$D$6>=(B1*0.95))))
The High values are slightly harder, because we can't just multiply be 0 to cancel out anything too low, or over 105% of the target. We need to add a huge number like 1E+99 (a 1 with ninty-nine 0s after it) instead, so that the MIN will ignore them: SUMPRODUCT(MIN($D$1:$D$6+1E+99*(--($D$1:$D$6<B1)+--($D$1:$D$6>(B1*1.05)))))
The last steps are to decide which of these numbers is closer to the target, and then to find the Unique ID to match. The %closeness calculations are (TARGET - LOW)/TARGET and (HIGH - TARGET)/TARGET), and subtracting one from the other gives you 2-(HIGH + LOW)/TARGET - a Positive number means "High" is closer, a Negative number means that "Low" is closer, and 0 means they are both the same distance (I'll default this to the Low number). We then use SIGN to change it to ±1, add 2 to get 1,2 or 3 and finish up with CHOOSE to output our number. In pseudo-code, CHOOSE(2+SIGN(2-(HIGH+LOW)/TARGET),LOW,LOW,HIGH), and the full thing:
CHOOSE(2+SIGN(2-(SUMPRODUCT(MAX($D$1:$D$6*--($D$1:$D$6<=B1)*--($D$6>B1*0.95)))+SUMPRODUCT(MIN($D$1:$D$6+1E+99*(--($D$1:$D$6<B1)+--($D$1:$D$6>(B1*1.05))))))/B1),SUMPRODUCT(MAX($D$1:$D$6*--($D$1:$D$6<=B1)*--($D$6>B1*0.95))),SUMPRODUCT(MAX($D$1:$D$6*--($D$1:$D$6<=B1)*--($D$6>B1*0.95))),SUMPRODUCT(MIN($D$1:$D$6+1E+99*(--($D$1:$D$6<B1)+--($D$1:$D$6>(B1*1.05))))))
Now, we have a number. All we need to do is either use VLOOKUP, or use MATCH to get the row it is on, and INDEX to pull the data for that row:
Office 365:
=IFERROR(VLOOKUP(B1,$D$1:$E$6,2,FALSE),VLOOKUP(CHOOSE(2+SIGN(2-(MAXIFS($D$1:$D$6,$D$1:$D$6,"<="&B1,$D$1:$D$6,">="&(B1*0.95))+MINIFS($D$1:$D$6,$D$1:$D$6,">="&B1,$D$1:$D$6,"<="&(B1*1.05)))/B1),MAXIFS($D$1:$D$6,$D$1:$D$6,"<="&B1,$D$1:$D$6,">="&(B1*0.95)),MAXIFS($D$1:$D$6,$D$1:$D$6,"<="&B1,$D$1:$D$6,">="&(B1*0.95)),MINIFS($D$1:$D$6,$D$1:$D$6,">="&B1,$D$1:$D$6,"<="&(B1*1.05))),$D$1:E$7,2,FALSE))
Otherwise:
=IFERROR(VLOOKUP(B1,$D$1:$E$6,2,FALSE),VLOOKUP(CHOOSE(2+SIGN(2-(SUMPRODUCT(MAX($D$1:$D$6*--($D$1:$D$6<=B1)*--($D$6>B1*0.95)))+SUMPRODUCT(MIN($D$1:$D$6+1E+99*(--($D$1:$D$6<B1)+--($D$1:$D$6>(B1*1.05))))))/B1),SUMPRODUCT(MAX($D$1:$D$6*--($D$1:$D$6<=B1)*--($D$6>B1*0.95))),SUMPRODUCT(MAX($D$1:$D$6*--($D$1:$D$6<=B1)*--($D$6>B1*0.95))),SUMPRODUCT(MIN($D$1:$D$6+1E+99*(--($D$1:$D$6<B1)+--($D$1:$D$6>(B1*1.05)))))),$D$1:E$7,2,FALSE))
(Obviously, change $D$1:$D$6 and $D$1:$E$6 to your actual data table ranges, and B1 to the input-value range)
I am trying to use index match functions to determine the appropriate rate for the below table.
So for example a consumer loan that is for a person that owns property, the car is 2 years or less in age and the total loan to value ratio is less than 140% should return a value of 5.15%
I believe this is what you wanted...
I would use a series of nested if functions to evaluate which column of LTV I would want the value to come from.
"That is what is done in the AND( ) part. If the value is greater than the 110% and smaller than 140% let's do the Index Match on the 110% Column, Otherwise do it on the 140% Column."
You could extend this for more columns with more IFs in the false condition.
Then it is a simple INDEX match with concatenation. It searches for the three parameters all concatenated in a single range of concatenations.
Hope it helped.
Proof of Concept
In order to achieve the above I had to make a minor edit to your header to be able to distinguish between the two 140% columns.
The functions used in this answer are:
AGGREGATE function
MATCH function
INDEX function
ROW function
IFERROR function
I placed the main part of the formula inside the IFERROR function as a way of dealing with things that may be out of range or when not all the input have been provided. I then assumed that what you were basing your search on would be provided in a series of cells. In my example I assumed the questions would be asked in the range H3 to K3 and I place the results in L3.
The main concept is centered around the INDEX function. I specified the index range as being the height of your table and the width of the percentage rates. Or for this example D2:F9.
=IFERROR(INDEX($D$2:$F$9,row number, column number),"Not Found")
That is the easy part. That more challenging part is determining the row and column number to look in. Lets start with the column number as it is the slightly easier of the two. I assumed the ratio to look for, or rather the header of the column to look in would be supplied. I basically used this equation to determine the column number:
=MATCH(K3,$D$1:$F$1,0)
which in layman's terms is which column between D and F, counting column D as 1, has the value equal to the contents of K3. So now that there is a formula to determine the column, we can drop that into our original formula and wind up with:
=IFERROR(INDEX($D$2:$F$9,row number,MATCH(K3,$D$1:$F$1,0)),"Not Found")
Now we just need to determine the row number. This is the most complex operation. We are going to basically make a bunch of logical checks and take the first row that matches all the logical checks. The premise here is that a logical check is either TRUE or FALSE. In excel 0 is false an every other integer is TRUE. So if we multiply a series of logical checks together, only the one that is true in all cases will be equal to 1. The first logical check is the loan type. it will be followed by the living status and then the vehicle age.
=(H3=$A$2:$A$9)*(I3=$B$2:$B$9)*(J3=C2:C9)
now if you put that into an array formula you will get a series of true false or 1/0. We are going to use it inside an AGGREGATE function with a special feature. The AGGREGATE function will perform array like calculation for some of its functions. We are going to use function 15 which will do this. We are also going to tell the aggregate function to ignore all errors, which is what the 6 does. So in the end what we wind up doing is dividing each row number by the logical check. If the logical check is false or 0, it will generate a Div/0! error which aggregate will choose to ignore. In the end we wind up with a list of row which match our logical check. We then tell the aggregate that we want the first result with the ,1. so we wind up with a formula that looks like:
=AGGREGATE(15,6,ROW($A$2:$A$9)/((H3=$A$2:$A$9)*(I3=$B$2:$B$9)*(J3=C2:C9)),1)
While this does provide us with the row number we want, we need to adjust it to make it an index number. In order to do this you need to subtract the number of header rows. In this case 1. So the index row number is given by this formula:
=AGGREGATE(15,6,ROW($A$2:$A$9)/((H3=$A$2:$A$9)*(I3=$B$2:$B$9)*(J3=C2:C9)),1)-1
And when we substitute that back into the earlier equation for the row number, we wind up with the final equation of:
=IFERROR(INDEX($D$2:$F$9,AGGREGATE(15,6,ROW($A$2:$A$9)/((H3=$A$2:$A$9)*(I3=$B$2:$B$9)*(J3=C2:C9)),1)-1,MATCH(K3,$D$1:$F$1,0)),"Not Found")
I have 3 different cells like this in my Excel table:
[B1] = 2
[N50] = 5
[V25] = 10
I want to find in those cells the nearest number greater than a specific value. For example, if the value is 1 then the number should be 2 in cell [B1]. If the value is 4 then the number should be 5 in cell [N50].
=IF(A2<LARGE(CHOOSE({1,2,3},D2,F3,H1),1),
IF(A2<LARGE(CHOOSE({1,2,3},D2,F3,H1),2),
IF(A2<LARGE(CHOOSE({1,2,3},D2,F3,H1),3),
LARGE(CHOOSE({1,2,3},D2,F3,H1),3),
LARGE(CHOOSE({1,2,3},D2,F3,H1),2)),
LARGE(CHOOSE({1,2,3},D2,F3,H1),1)),
"larger or equal to all searched numbers")
and in one nice straight line for copy and paste purposes:
=IF(A2<LARGE(CHOOSE({1,2,3},D2,F3,H1),1), IF(A2<LARGE(CHOOSE({1,2,3},D2,F3,H1),2), IF(A2<LARGE(CHOOSE({1,2,3},D2,F3,H1),3), LARGE(CHOOSE({1,2,3},D2,F3,H1),3), LARGE(CHOOSE({1,2,3},D2,F3,H1),2)), LARGE(CHOOSE({1,2,3},D2,F3,H1),1)), "larger or equal to all searched numbers")
The hardest part for me and I did not understand it and still do not...just accepting, is building your separate cells into an array. That part is done by the CHOOSE():
CHOOSE({1,2,3},D2,F3,H1)
Once it is in an array, perform a large function to sort it from largest to smallest. Then through a series of nested IF statements, checked to see if the specified number in A2 was smaller than the K largest number.
Here is a proof of concept scaled down to smaller range but give you the idea.
Now I did it with a large, you could have done it with a small function as well, you would just need to alter your logic in the if statements.
This is an alternative approach without the if statements:
=IF(A2>=MAX(A7,C8,E6),"Greater than or equal to all options",INDEX(CHOOSE({1,2,3},A7,C8,E6),IFERROR(MATCH(A2,CHOOSE({1,2,3},A7,C8,E6),1)+1,1)))
I have the situation of the picture
.
A table and two data: a rating value and another value. I need to look up to the matrix along the right row based on the current rating and sweep horizontally based on the input value and get the nearest smaller rating.
So in this case, I'm expecting 2. If the rating were 2, then results should be 3 and with 3, then 2.
Try this formula:
=INDEX(B1:D1,MATCH(B7,INDEX(B2:D4,MATCH(B6,A2:A4,0),0)))
The inner INDEX/MATCH sets the proper range. While the outer finds the first time that the value number is equal to or less than and the next is greater than.
EDIT: As per the OP's comment
If you want the next column just add one:
=INDEX(B1:D1,IFERROR(MATCH(B7,INDEX(B2:D4,MATCH(B6,A2:A4,0),0))+1,1))
The IFERROR deals with the times that the value is less than the first number in the series.