Excel IF Function (3 Values) - excel

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", "")))

Related

Excel formula for between time frames

not sure if stack also accepts/allows general excel questions but figured I'd ask anyway. Looking for help with the excel formula that checks the time in one column and returns the shift (day, night or overnight) in another column. I have the night and overnight shifts outputting correctly but for some reason the day shift does not?
Here are the two excel formulas:
=IF(AND(HOUR(Table8[#Time]) >7, HOUR(Table8[#Time] <15)),"1st shift")
=IFS(AND(HOUR([#Time]) >= 7, HOUR([#Time] <= 15)), "1st shift", AND(HOUR([#Time]) >= 15, HOUR([#Time]) <= 23), "2nd shift", OR(HOUR([#Time]) >= 23, HOUR([#Time]) <= 7), "3rd shift")
The parenthesis is the issue here
Check it out like this
=IFS(AND(HOUR([#Time]) >= 7, HOUR([#Time]) <= 15), "1st shift", AND(HOUR([#Time]) >= 15, HOUR([#Time]) <= 23), "2nd shift", OR(HOUR([#Time]) >= 23, HOUR([#Time]) <= 7), "3rd Shift")
you put the bracket at the wrong place for the second check for the 1st shift
This is correct:
=IFS(AND(HOUR([#Time]) >= 7, HOUR([#Time]) <= 15), "1st shift", AND(HOUR([#Time]) >= 15, HOUR([#Time]) <= 23), "2nd shift", OR(HOUR([#Time]) >= 23, HOUR([#Time]) <= 7), "3rd shift")
HOUR([#Time] <= 15) is wrong

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

AVERAGEIFS: Weighted rankings

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.

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")))

Dynamic Programming: Finding the number of ways in which a order-dependant sum of numbers is less than or equal to a number

Given a number N, and a set S of numbers, find the number of ways in which a order-dependant sum of numbers of S is less than or equal to N. The numbers in S can occur more than once. For example, when N = 3 and S={1, 2}, the answer is 6. In this example, 1, 1+1, 2, 1+1+1, 1+2, 2+1 are less than or equal to 3.
When S = {1, 2}, the answers for N = 0, 1, 2... are 0, 1, 3, 6, 11, 19, 32.... Think about why these numbers might be the same as the Fibonacci sequence with 2 subtracted.
When S={n1, n2, …, nk}, you have f(N)=f(N-n1)+f(N-n2)+…+f(N-nk). So you just have to compute f(i) for i < nk and then you can easily compute f(n) with the formula (f(n),f(n+1),…,f(n+nk))=(f(0),f(1),…,f(nk))*A^n where A is the companion matrix of the sequence.

Resources