AVERAGEIFS: Weighted rankings - excel

I have a formula for calculating rankings of certain events across different organizations:
=AVERAGEIFS(C2:C100, B2:B100, "A", C2:C100, ">0") * IF(COUNTIF(B2:B100, "A") < 3, 0.7, IF(COUNTIF(B2:B100, "A") < 10, 0.9, IF(COUNTIF(B2:B100, "A") > 30, 1.1, IF(COUNTIF(B2:B100, "A") > 50, 1.2, 1))))
This formula works, but for some reason, using data that I have, I know the AVERAGEIFS value for "A" should be multiplied by 1.2, as there are more than 50 instances of "A" in Col. B. The result the above formula gives multiplies by 1.1.
I've also tried to expand the above formula to incorporate additional factors that could affect the ranking:
=AVERAGEIFS(C2:C100, B2:B100, "A", C2:C100, ">0") * IF(COUNTIF(B2:B100, "A") < 3, 0.7, IF(COUNTIF(B2:B100, "A") < 10, 0.9, IF(COUNTIF(B2:B100, "A") > 30, 1.1, IF(COUNTIF(B2:B100, "A") > 50, 1.2, 1)))) * IF((AND(B2:B100, "A"), COUNTIF(S2:S100, "yes")>1), 1.1, 1))
Running this second formula gives me an error message: "The formula you typed contains an error."
Not sure what's going wrong in the second formula, as I've continued to build on the first formula above.

Since 30 is less than 50 your formula (which short-circuits) never gets as far as what is more than 30 as a separate condition. Maybe something like:
=AVERAGEIFS(C2:C100, B2:B100, "A", C2:C100, ">0") * IF(COUNTIF(B2:B100, "A") < 3, 0.7, IF(COUNTIF(B2:B100, "A") < 10, 0.9, IF(COUNTIF(B2:B100, "A") > 50, 1.2,1))))
This relies in the default factor of 1 for values of 10 to under 30.
Might be easier to see what is happening with:
LOOKUP(COUNTIF(B2:B100,"A"),{0,3,10,30,50},{0.7,0.9,1,1.1,1.2})
after the asterisk.

Related

If the product of two numbers is equal to one of the numbers in the column then return the value from the level column

I need two excel formulas: for V level and for R level.
Based on the product of numbers a and b, numbers 1-25 are obtained, which are classified into 5 levels (1-5).
The first formula should return the V level of numbers 1-5 based on the product of classified numbers 1-25.
The second formula should return the R level of the numbers I, II, III, IV, V along with the corresponding color.
I tried with the excel formulas: VLOOKUP, INDEX and MATCH, and some other combinations but it doesn't work.
Edit: What I've tried so far:
=INDEX(D18:D22;MATCH(C5*D5;H18:H22;0))
=VLOOKUP(C5:D5;D18:H22;5;FALSE)
=IF(ISNUMBER(MATCH(C5*D5;D18:D22;0));VLOOKUP(C5*D5;D18:H22;5;FALSE))
First option:
Bojan, you can solve this like below with index and vlookup.
In order to use vlookup, first you need to spread your legend table like I did in below screenshot.
C9: =INDEX(D3:H7,B4,E1)
C10: =VLOOKUP(C9,$C$12:$D$25,2,FALSE)
H9: =INDEX(D3:H7,C10,H1)
H10: =VLOOKUP(H9,$C$12:$E$25,3,FALSE)
Orange cells need your manual input.
Second option (after your comment):
After adding below built-in function into a module of your excel file, you will not need the legend table for calculation. Just call your built-in function to get your levels.
Function get_level(levelType As String, value As Integer) As String
If levelType = "V" Then
Select Case value
Case 1, 2
get_level = "1"
Case 3, 4, 5
get_level = "2"
Case 6, 8, 9
get_level = "3"
Case 10, 12, 15, 16
get_level = "4"
Case 20, 25
get_level = "5"
End Select
ElseIf levelType = "R" Then
Select Case value
Case 1, 2
get_level = "I"
Case 3, 4, 5
get_level = "II"
Case 6, 8, 9
get_level = "III"
Case 10, 12, 15, 16
get_level = "IV"
Case 20, 25
get_level = "V"
End Select
End If
End Function

IF function for if x > y, but < yz multiple by b

So this is what I’m trying to do. If the percent of an output (let’s call it A1) is <75% multiply by 0. If it’s between 75-100% multiply by 1, if it’s between 100-150% multiply by 2, etc.
Scott Craner's MATCH answer is already good in the comments. But if you are looking for a plain IF function:
=IF(A1 < 0.75, 0,
IF(A1 < 1, B1,
IF(A1 < 1.5, B1 * 2)))
Although, I recommend using IFS for readability since we can opt not to include else values due to the non-conflicting conditions.
=IFS(
A1 < 0.75, 0,
A1 < 1, B1,
A1 < 1.5, B1 * 2
)
Sample Output:
Note:
Sheets read the formula left to right (top to bottom) so if it doesn't match the first condition, it will just proceed to the next one.
Feel free to adjust the ranges if it must be inclusive to the upper limit. (e.g < to <=)
Notice that 1st and 2nd values were not multiplied by 0 and 1, as we all know, the result would be 0 and the number itself respectively thus I opted from multiplying B1 to those numbers.
Sample outputs in the sheet shown are respective to their rows.
use:
=INDEX(IFNA(VLOOKUP(A1, {0.75, 0; 1, B1; 1.5, B1*2}, 2, 0)))

Excel IF Function (3 Values)

Please help me out with this one in Excel.
I used this one but does not work
=IF(Q67 < 6, "D", IF(Q67 > 6 < 11, "M", IF(Q67 > 10, "E", "")))
This should go like this:
E- Greater than 11
D - Less than 6
M - Greater than 5 but not equal to 11
Your answers will be appreciated. Thank you :)
First issue, the ranges overlap...
So, assuming my correction is valid you could try:
=if(Q67>11,"E",if(Q67<6,"D","M"))
Try,
=IF(Q67 < 6, "D", IF(Q67 < 11, "M", "E"))
'testing if Q67 is not blank as well
=IF(Q67="", "", IF(Q67 < 6, "D", IF(Q67 < 11, "M", "E")))
If Q67 is not less than 6 it fails the first test and moves on to the second. You don't need to check if Q67 is greater or equal to 6 at that point because if it wasn't greater or equal to 6 it wouldn't be there in the first place.
However, it may be important to understand how two conditions work.
=IF(Q67 < 6, "D", IF(AND(Q67 >= 6, Q67 < 11), "M", IF(Q67 >= 11, "E", "")))

Declare value based on date range without year

I have about 10000 records in an Excel sheet (although I can import into Access 2010 if easier) and I need to set a value in a separate column if the dates fall between certain planting seasons. Year is irrelevant.
Thus if a date falls between a certain range, the column is filled in with its appropriate planting season.
Spring = 3/16 - 5/15
Summer 5/16-8/15
Fall 8/15-10/31
Everything else is Null
3/20/2015 and 4/16/2013 are both "Spring" in the seasons column
6/28/2011 and 8/1/2015 are both Summer, etc.
Ideas as to how I can do this? As I said I can do it in either Excel or Access, whichever approach is easier.
You can use the DateSerial Function in an Access query. For example your spring season for planting date could be expressed as ...
planting_date BETWEEN DateSerial(Year(planting_date), 3, 16) AND DateSerial(Year(planting_date), 5, 15)
You could use similar patterns in a Switch expression to determine the planting season for each planting_date ...
SELECT
y.planting_date,
Switch
(
y.planting_date BETWEEN DateSerial(Year(y.planting_date), 3, 16) AND DateSerial(Year(y.planting_date), 5, 15), 'spring',
y.planting_date BETWEEN DateSerial(Year(y.planting_date), 5, 16) AND DateSerial(Year(y.planting_date), 8, 15), 'summer',
y.planting_date BETWEEN DateSerial(Year(y.planting_date), 8, 16) AND DateSerial(Year(y.planting_date), 10, 31), 'fall',
True, Null
) AS season
FROM YourTable AS y;
If you want to store those season values in a field named planting_season, use the Switch expression in an UPDATE query ...
UPDATE YourTable AS y
SET y.planting_season =
Switch
(
y.planting_date BETWEEN DateSerial(Year(y.planting_date), 3, 16) AND DateSerial(Year(y.planting_date), 5, 15), 'spring',
y.planting_date BETWEEN DateSerial(Year(y.planting_date), 5, 16) AND DateSerial(Year(y.planting_date), 8, 15), 'summer',
y.planting_date BETWEEN DateSerial(Year(y.planting_date), 8, 16) AND DateSerial(Year(y.planting_date), 10, 31), 'fall',
True, Null
);
This formula assumes the first date is in cell A1. Enter the formula in cell B1 (or another empty cell from row 1):
=CHOOSE(MATCH(A1-DATE(YEAR(A1),1,0),{0;75;136;227;305},1),"","Spring","Summer","Fall","")
Now copy downward as far as needed.
That's it.
Note: this works by calculating the day of the year, for example March 16 is the 75th day of the year. Once the 'day of the year' is calculated, a simple binary match is performed on an array of day numbers that correspond to your planting seasons. Finally, the CHOOSE function is used to translate the MATCH results to the name of the season.
To edit your planting schedule, simply adjust this 'days of the year' array: {0;75;136;227;305}
Note: this is an extremely efficient self contained formula. No external helper columns are required and there are no IF functions, nested or otherwise.
Addendum: here is a variation that has a clause that deals with Leap Year:
=CHOOSE(MATCH(A1-DATE(YEAR(A1),1,0),{0;75;136;227;305}+(2=MONTH(DATE(YEAR(A1),2,29))),1),"","Spring","Summer","Fall","")
A few of helper columns to extract month and date would be useful (Assume values are at A1:A1000):
B1 = MONTH(A1)
C1 = DAY(A1)
D1 = DATE(2000, B1, C1)
We intentionally "cheat" about the year for easier comparison.
After that, there's nothing special to do here, just a lot of nested ifs:
IF(AND(D1 >= DATE(2000, 3, 16), D1 <= DATE(2000, 5, 15)), "Spring",
IF(AND(D1 >= DATE(2000, 5, 16), D1 <= DATE(2000, 8, 15)), "Summer",
IF(AND(D1 >= DATE(2000, 8, 16), D1 <= DATE(2000, 10, 31)), "Fall", "Winter")))

if statement in microsoft excel

this is my statement
=IF(G7 < 6, G7 * D22) + IF(5 < G7 < 11, G7 * D23) + IF(10 < G7, G7 * D24)
it works if G7 cell value is less then 6 or greater then 10, but if G7 value is from 6 to 10 the result is 0.
Cell D23 has value of 15.
What can be wrong?
Thank you
A wild guess, but you might want to edit the middle statement to this;
IF(AND( G7 < 5, G7 < 11), G7 * D23)
In the "Formulas" tab, "Formula Auditing" section you will find an "Evaluate Formula" button. This will show you the issue.
In the IF(5 < G7 < 11, G7 * D23) statement, when G7=6, the "5 < 6" portion evaluates to "TRUE". Next, this is evaluated as "TRUE < 11", which returns FALSE. This can be fixed by evaluating the comparisons to 5 and 11 separately.
IF(AND(5 < G12,G12 < 11), G12 * $D$23)
Personally, I would explicitly state the [value if false], but that's not strictly necessary.
=IF(G7 < 6, G7 * D22,0) + IF(AND(5 < G7,G7 < 11), G7 * D23,0) + IF(10 < G7, G7 * D24,0)
Try like this
=IF(G7<6,D22,IF(G7<11,D23,D24))*G7
You don't need an AND when you have nested IFs because the first IF has already dealt with <6 values so when the second IF is processed you only need the upper bound, similarly there is no 3rd IF because after the first two IFs all remaining values must fall in category 3
Mr. Pankaj Jaju gave correct answer.
=IF(G7 < 6, G7 * D22) + IF(AND( G7 >= 6, G7 < 11), G7 * D23) + IF(G7>=11, G7 * D24)
I tried it (actually I put AND(G7 > 5 instead of G7 >= 6), but it is the same) and it works.
Thank you

Resources