percent_rank special case to not include the value being evaluated in the range of group to be evaluated - excel

Consider these values:
company_ID 3yr_value
1 10
2 20
3 30
4 40
5 50
I have this statement on my query and my goal is to compute for the percent rank of value 50 in the group
round(((percent_rank() over (partition by bb.company_id order by bb.3yr_value)) * 100))
in excel, this is equivalent to
=percentrank(b1:b5,b5)
BUT, what I need is an equivalent to this 1:=percentrank(b1:b4,b5) -- notice that I don't include A5 in the range that needs to be evaluated. I'm out of options, and already consulted Mr. Google but it seems I still cant find the solution. I always end up including B5 in my query.
I'm using postgres sql

Related

Excel pass/fail which only triggers the fail after 2 values don't meet the requirements

I'm trying to write a pass/fail check that returns a fail only after 2 values in the range fail to pass the check. I've wrote the start of the check however it already returns the "Fail" straight after the first failing value.
For example: Pass/Fail check if all values are above 20.
20
20
20
---
good
20
19
20
---
still good
28
10
19
---
fail (since 2 values fail to meet the required value)
In my sheet 5 values need to be checked which need to be in a certain range defined in a other location (XX1 and XX2 in formula). The formula I used so far is:
=IFS(AND(E37:E41>=MIN(XX1);E37:E41<=MAX(XX2));"Pass";TRUE;"Fail")
There are multiple options:
Using COUNTIFS and COUNTA:
=IF(COUNTIFS(E37:E41,">="&XX1,E37:E41,"<="&XX2)>COUNTA(E37:E41)-2,"Pass","Fail")`
If you need to also check that the average falls between XX1 and XX2, then use AND and AVERAGE along with the formula above.
=IF(AND(COUNTIFS(E37:E41,">="&XX1,E37:E41,"<="&XX2)>COUNTA(E37:E41)-2,AVERAGE(E37:E41)>=XX1,AVERAGE(E37:E41)<=XX2),"Pass","Fail")`
3 Conditions IF Statement
AVERAGE(E37:E41)>=XX1
AVERAGE(E37:E41)<=XX2
COUNTIF(E37:E41,"<20")<2 i.e. not more than 1 value is lt 20 (or at least 4 values are gte 20).
=IF(AND(AVERAGE(E37:E41)>=XX1,AVERAGE(E37:E41)<=XX2,COUNTIF(E37:E41,"<20")<2),"Pass","Fail")

Excel formula for greater than but less than with several tiers

I have a few hundred rows of data, and each has a number between 1 and 200, and I'd like to put them in categories of 1-5 depending on where that number is.
The categories look like this:
Zones Min Max
1 0 35
2 35 60
3 60 85
4 85 110
5 110 200
I want to assign it a Zone if it is greater than the Min, but less than the Max.
I have 2 formulas I've been working with to solve it. One is a nested IF AND statement:
=IF(A1<=35,1,IF(AND(A1<=60,A1>35),2,IF(AND(A1<=85,A1>60),3,IF(AND(A1<=110,A1>85),4,IF(AND(A1<=200,A1>110),2,"TOO BIG")))))
The 2nd formula attempts to use a SUMPRODUCT function:
=INDEX($C$2:$C$6,SUMPRODUCT(--(A1<=$E$2:$E$6),-- (A1>$D2:$D$6),ROW($2:$6)))
Rather than have to continue to adjust the numeric values manually, I set them as absolutes, which is why this formula is slightly different. The E column is the Max value set, and the D is the Min value set.
Any help would be appreciated!
Use this:
=MATCH(A1,{0,35,60,85,110})
Another way is to use VLOOKUP and you just need to set the min number:
=VLOOKUP(D2,$A$2:$B$6,2,1)
The key is the 4th parameter needs to set to 1 which means TRUE. It will find the closest value and return the zone for you.
But noticed that you have overlaps like 35 or 60 etc. that you will need to adjust your value column.

Percentile function across multiple arrays

So I have this data in excel right now
A B C
2015-1 Test 1 23
2015-2 Test 1 12
2015-3 Test 1 43
2015-4 Test 1 32
2015-5 Test 1 3
2015-6 Test 1 90
2015-1 Test 2 200
2015-2 Test 2 123
2015-3 Test 2 21
2015-4 Test 2 40
2015-5 Test 2 17
2015-6 Test 2 138
2015-1 Test 3 160
2015-2 Test 3 55
2015-3 Test 3 30
2015-4 Test 3 74
2015-5 Test 3 67
2015-6 Test 3 89
Right now, I have it so that the user can look at the a specific time period, not necessarily all of the dates, of data, (for example, from 2015-1 to 2015-4). So when the user selects the date that they want, I want to take the percentile of the data(column C) at that date across all of the different test scenarios in column B. Right now there is only 3, but there will be up to 100 different test cases.
I know its possible to do =Percentile((test1_data,test2_data,test3_data),1),
but I'm going to have to do the percentile across over 100 difference test cases, and the way I have it set up now seems highly inefficient. Is there a way to do this without having to enter in all of the 100 different arrays by hand?
Based on your table, something along the lines of the following formula should work. (It is an array formula and you should use CTL+SHIFT+ENTER as you enter the formula into the cell to activate the function.)
{=PERCENTILE(
IF(NUMBERVALUE(LEFT($A$1:$A$18,4))<=EndYear,
IF(NUMBERVALUE(LEFT($A$1:$A$18,4))>=BegYear,
IF(NUMBERVALUE(RIGHT($A$1:$A$18,1))<=EndMonth,
IF(NUMBERVALUE(RIGHT($A$1:$A$18,1))>=BegMonth,
$C$1:$C$18)))),1)}
EndYear is a reference to the cell that has the LAST year you want included
BegYear is a reference to the cell that has the FIRST year you want included
EndMonth is a reference to the cell that has the LAST month (or whatever the second unit is) you want included
BegMonth is a reference to the cell that has the FIRST month (or whatever the second unit is) you want included
Just expand the references $A$1:$A$18 and $C$1:$C$18 to include however many test cases you want.
FORMULA EXPLANATION
The first two if statements focus on the year. They take the LEFT() four digits as a string. NUMBERVALUE() then turns strings into values. You can then use the if statement to logically evaluate whether the test dates fall into the desired range of dates.
The second two if statements do precisely the same thing on the last single-digit (month?)
The embedded if statements, will return an array of the associated value from column C if all the statements are true and FALSE if one of the statements is not true.
PERCENTILE() will take the array, ignore the items that returned as FALSE, and provide you with the k-th percentile of the range of values in which all four if statements are true.
*As a note, I don't know the significance of your second digit. If it ever goes above 9, you might need to adjust for your data. In that case you could either replace all the 2015-9 entries with 2015-09 and change the second argument of the RIGHT() function to 2, or you could do something like MID($A$1:$A$18,6,2) or the last digit could just be replaced by however many characters you have after the year argument.

Create a formula that returns a minimum date from a range based on cell values in another column

I am looking for a formula that will return the earliest date from a column, based on the contents of values in other cells. (Actually I want a Min and Max date, but am assuming the Max will be identical to any Min solution )I know I can return the date I want just by using MIN and specifying the range of cells I want, but I ideally want the formula to be dynamic. I have looked around and believe I possibly need to use a combination of index and match, but cant find any examples that use Min and Max. I have considered using dynamic named ranges to define my task groups, but that would mean having to define a static number of task groups, and there could be many task groups.
The sheet below shos some sample date on the left of the workbook, with the summary data on the right. The "hidden worker column" was an idea I had that I though might make the solution easier. So I want the summary data on the right to use either column A, or column B if its easier, to display the min and max dates based on the section number in column F - Is this possible without VBA?
#mthierer's link is good. If you wanted to remove the need to add a "helper column", you could try (data in A1:C10; summary table in E1:G2):
{=MIN(IF(ROUNDDOWN($A$1:$A$10, 0)=$E1, $B$1:$B$10))} (or {=MAX(...)} with $C$1:$C$10)
Note that you have to enter the formula as an array formula with CtrlShiftEnter.
Data (A1:C10):
1 23 57
1.1 42 91
1.2 35 100
1.3 39 80
1.4 28 51
1.5 30 96
2 33 52
2.1 11 73
2.2 48 80
2.3 16 59
Summary Results (E1:G2):
1 23 100
2 11 80

How to return a value from a range of values

I would appreciate it if someone can answer this.
Lets say I got multiple rows with three column with min, max and the return value . And I wanted to create a single formula to search the min and max value and then gave back a return value based on the row . Let me just show it :
Min Max Return
0.01 10 0
10.01 20 5
20.01 30 12
30.01 40 15
Input 7 <---- User input
Return 0 <---- This should be calculated based on the user input against the table
Input 33 <---- User input
Return 15 <---- This should be calculated based on the user input against the table
If you mean a SQL Query, here is the query that jsut do the job for you :
SELECT Return from TABLE_Name
WHERE
Input >= Min AND Input < Max
Ok, I'll attempt another try:
=SUMPRODUCT(C2:C5*(F1>=A2:A5)*(F1<=B2:B5))
C2:C5 are the results, A2:A5 the minmum values, B2:B5 the maximum values and F1 the actual value.
Basically, SUMPRODUCT can be used as it does the calculation for every row and sums up the results. If the test succeeds, 1 is returned, otherwise 0. Thus, only the successful test will have a 1, all others will multiply their result with 0.
If I understood the question correctly, some nested IFs would do like (assuming input in A4 and the ranges like in the table):
=IF(AND(A4>B1,A4<B2),B3,IF(AND(A4>C1,A4<C2),C3,...
For more complex (meaning longer) tables you could also use a "helper" column (Column D):
IF(AND($A$4>B1,$A$4<B2),B3,"")
"drag" this down to copy it and then sum the column to get the result.
All a bit of a mess, but I can't think of any more elegant solution using excel formulas.

Resources