IF Statments in EXCEL - excel

I am trying to calculate different price decreases when each statement is true for example
Statement 1 - Y
Statement 2 - N
Statement 3 - N
Statement 4 - N
I have been able to get it to work with one of the statements being true using
=IF(EXACT(L9,"Y"),I29-I9*C21,I29)
However, I don't know how I would be able to add that together if all 4 of the statements were Y as each of the statements is taking away different amounts of money if True.
My guess for it was
=IF(EXACT(L9,"Y"),I29-I9*C21,I29,IF(EXACT(L8,"Y"),I32-I8*C20,I32))
however, to many arguments were being made for the function
any help would be much apricated :)
This is what my excel document looks like at the moment. Don't think I did very well trying to explain it :/.
Excel Document
So more or less what I have been trying to do is when bought is changed to Y it would change that total however I've only been able to find out how to do it with one statement which has been changed to Y using:
=IF(EXACT(J6,"Y"),H18-H6*I6,H18)
sorry for the lack of being to explain much :/

This is how you can build more complex logical functions with IF statements.
If all four statements equal "Y"....
=if(and(A1="Y",B1="Y",C1="Y",D1="Y"),[Calculation if True],[Calculation if False])
So, here is an example of multiple tests nested in a statement.
Test 1: Are all 4 cells equal to "Y"?
If yes, then "Test 1 equals True".
If not,
Test 2: Are the first 3 cells equal to "Y" and the 4th cell equal "N"?
If yes, then "Test 2 equals True"
If not, "Neither Test 1 or Test 2 equal True"
This is the formula:
=if(and(A1="Y",B1="Y",C1="Y",D1="Y"),"Test 1 equals True",if(and(A1="Y",B1="Y",C1="Y",D1="N"),"Test 2 equals True","Neither Test 1 nor Test 2 equal True"))

Related

Excel Statement with 4 conditions and 4 answers

All of the methods that I've used have 2 answer values (True or False).
How can I get the following with a formula?
If A1=1 then it's 11, if A1=2 the answer is 22, if A1=3 then it's 33, if A1=4 it's 44.
If the value your are evaluating is in cell A1, then the nested function would be as follows:
IF(A1=1,11,IF(A1=2,22,IF(A1=3,33,IF(A1=4,44,""))))
I put the 2 double commas at the end so the formula returns a blank instead of false.
I don't know if that's what you are asking about, but you can make multiple (nested) IF statements in one. For example:
IF(1=2;TRUE;IF(2=2;TRUE;FALSE))
You just put another IF in the FALSE part of IF statement. If that's not it, can you give a piece of the statement you tried and precise more what do you want?
=IF(AND(INT(A1)=A1,A1<=4,A1>=1),A1*11,"")
Now the above works for the condition you placed in your example, however if one were to go by your title alone you have a couple of options you could go with.
You first Option would be nested IF statements. Like you said each IF function has TRUE or FALSE. The trick is to put another IF function in for the TRUE result and another in for the FALSE results
IF(CHECK1, IF(CHECK2, TRUE2, FALSE2),IF(CHECK3, TRUE3, FALSE3))
The above give 4 potential results based on only 3 checks. Another option would be to do a check and supply a value for a TRUE result and another IF for a false result. Keep repeating the process. Conversely you could go the same route flipping TRUE FALSE option. It might look something like this:
IF(CHECK1, TRUE1, IF(CHECK2, TRUE2, IF(CHECK3, TRUE3, FALSE3)))
FALSE3 would be the result of all previous checks failing.
So for your case, your nested IF could look like (assuming the only valid entries are 1, 2, 3 and 4):
IF(A1=1,11,IF(A1,2,22,IF(A1=3,33,44)))
OR
IF(ISODD(A1),IF(A1=1,11,33),IF(A1=2,22,44))
and there are other options to work through the logic. there are also other checks you could be doing and results being displayed if your entries in A1 were not limited to the integers 1,2,3 and 4.
Now because you example is using the sequential integers 1,2,3 and 4 you could also use the CHOOSE function. Alternatively if you can make your criteria evaluate to sequential integers stating at 1 the CHOOSE function would work as well. Supply choose with an integer as the first argument and it will return the corresponding argument in the list that follows
CHOOSE(ARGUMENT,RESULT1, RESULT2,...,RESULTn-1, RESULTn)
In your case it would look something like:
CHOOSE(A1,11,22,33,44)
If you can not get sequential numbers for whatever reason and the gap is numbers is small and you are in the low integer count, you could leave a gap in results by providing "", or 0). lets say you has 1,3 and 4 as potential arguments, then your choose might look like:
CHOOSE(A1,11,"",33,44)
=IF(A1<>"",INDEX({11;22;33;44},A1),"")
=IF(AND(ISNUMBER(A1),A1<=4),A1*11,"")

Logic evaluation problem in SUMPRODUCT Formula

I am using a formula based on SUMPRODUCT, SUBTOTAL, and OFFSET. To enable count of visible rows only with criteria. I a trying it on a simple sample data which as follows. Data starts from B4 in the Range B4:B12 Header B3:
B Column
HD
2
2
4
6
2
1
8
9
2
Formula is :
=SUMPRODUCT((B4:B12=B4)*(SUBTOTAL(103,OFFSET(B4,ROW(B4:B12)-MIN(ROW(B4:B12)),0))))
It gives correct result of 4 counts for a value of 2.
I went for evaluation of the formula to fully understand its logic. I could comprehend major part of its logic but certain steps are not quite clear to me. I am reproducing evaluation steps below with my comments.
Step -1
=SUMPRODUCT(({2;2;4;6;2;1;8;9;2}=2)*(SUBTOTAL(103,OFFSET(B4,ROW(B4:B12)-MIN(ROW(B4:B12)),0))))
OK
Step -2
=SUMPRODUCT(({TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE})*(SUBTOTAL(103,OFFSET(B4,ROW(B4:B12)-MIN(ROW(B4:B12)),0))))
OK
STEP-3
=SUMPRODUCT(({TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE})*(SUBTOTAL(103,OFFSET(B4,ROW(B4:B12)-MIN(ROW(B4:B12)),0))))
OK
STEP-4
=SUMPRODUCT(({TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE})*(SUBTOTAL(103,OFFSET($B$4,{4;5;6;7;8;9;10;11;12}-MIN({4;5;6;7;8;9;10;11;12}),0))))
OK
STEP-5
=SUMPRODUCT(({TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE})*(SUBTOTAL(103,OFFSET($B$4,{4;5;6;7;8;9;10;11;12}-4),0))))
OK
STEP-6
=SUMPRODUCT({TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE}*(SUBTOTAL(103,OFFSET($B$4,{0;1;2;3;4;5;6;7;8},0))))
Why {0;1;2;3;4;5;6;7;8} ??
STEP-7
=SUMPRODUCT({TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE}*(SUBTOTAL(103,{#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;})))
Why {#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;} ??
STEP-8
=SUMPRODUCT({TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE}*({1;1;1;1;1;1;1;1;1}))
How 1 instead of #VALUE!
STEP-9
=SUMPRODUCT({1;1;0;0;1;0;0;0;1})
OK
Step -10
4
OK
I am not having full clarity on the following points
STEP-6 : Why {0;1;2;3;4;5;6;7;8}
STEP-7: Why {#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;}
STEP-8: How 1 instead of #VALUE!
Hope Someone helps in clarifying the logic behind these mentioned spots. Please forgive me for asking clarity on such a trivial matter.
STEP-6 : Why {0;1;2;3;4;5;6;7;8}
Because the {4;5;6;7;8;9;10;11;12}-4 evaluates to {4-4;5-4;6-4;7-4;8-4;9-4;10-4;11-4;12-4} which is {0;1;2;3;4;5;6;7;8}
STEP-7: Why {#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!}
The formula evaluator fails getting the values out of the 9 cell references got via OFFSET($B$4,{0;1;2;3;4;5;6;7;8},0) = {$B$4;$B$5;$B$6;$B$7;$B$8;$B$9;$B$10;$B$11;$B$12} in array context. But that does not matter because:
STEP-8: How 1 instead of #VALUE!
the SUBTOTAL(103,... is a COUNTA subtotal which, for each single cell reference of the 9 cell references got in step 7, counts 1 if it is not hidden, else 0. So it does not matter whether the cell values was evaluated or not.
Btw.: The same can be achieved using
=SUMPRODUCT((B4:B12=B4)*(SUBTOTAL(103,INDIRECT("B"&ROW(B4:B12)))))
Annotation:
Such formulas are result of trial and error. I doubt any Excel programmer was able predicting all usages of the functions they implemented. There are usages of Excel functions in the wild which are as much thought outside the box that they originally could not have thought so.
Bonus:
=SUMPRODUCT(OFFSET(B4,ROW(B4:B12)-MIN(ROW(B4:B12)),0))
results in 0 using your values in B4:B12.
Here the formula evaluator also fails getting the values out of the 9 cell references got via OFFSET($B$4,{0;1;2;3;4;5;6;7;8},0) = {$B$4;$B$5;$B$6;$B$7;$B$8;$B$9;$B$10;$B$11;$B$12} in array context. And the result is {#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!}. But now it matters because we need the values.
In that case we can use N function to force getting the values
=SUMPRODUCT(N(OFFSET(B4,ROW(B4:B12)-MIN(ROW(B4:B12)),0)))
This results in 36, the sum of your values in B4:B12.

combining IF and AND statement not working in excel

I am trying to calculate the percentage, here the rules are as follows:
01. Employees working in IT department for more than 10 years will get 7% and rest of the IT guys will get 6.5%
02. And for rest of the departments, we have different percentages
Here H column represents various departments and F is working experience and in column I we're getting the main value from which we have to calculate the percentages.
Here's what I tried
=IF(AND(H5="IT",F5<10),I5*6.5%,I5*7%,IF(H5="PRODUCTION",I5*9%,IF(H5="MARKETING",I5*6%,IF(H5="LAW",I5*6%,IF(H5="HR",I5*9.36%)))))
This is showing You've entered too many arguments
Your first If statement, really had one too many argument.
=IF(AND(H5="IT",F5<10),I5*6.5%,IF(H5="PRODUCTION",I5*9%,IF(H5="MARKETING",I5*6%,IF(H5="LAW",I5*6%,IF(H5="HR",I5*9.36%,I5*7%)))))
Since each new if is nested as the FALSE eventuality. Look at the end for that 7%.
Edit:
My bad(reading your comment made me realize), there are two error in your formula.
One has been discussed, the second is how you nested those IT percentage.
=IF(AND(H5="IT",F5>=10),I5*7%,IF(AND(H5="IT",F5<10),I5*6.5%,IF(H5="PRODUCTION",I5*9%,IF(H5="MARKETING",I5*6%,IF(H5="LAW",I5*6%,IF(H5="HR",I5*9.36%,""))))))
In this version I added another IF statement. We could have avoided it by defining either one of the IT's rate as the ELSE result same as my initial answer. Now all predictable eventuality have their own TRUE match. An unexpected value will return an empty string. Maybe you want it to be 0 instead...
(1) IF(AND(...))= conditions
(2) I5 * 6.5% = value if true
(3) I5 * 7% = value if false
Therefore, you already indicate value if false and another if statement is not allowed. I would remove (3) and put it to the very end of your formula. As such, once none of the previous conditions are met, it will automatically take on the value of 7%.

If-Else ladder in Excel To sort data

I was doing R&D on Excel. And wanted to use If-else ladder in column of excel.
Let's say I have a 2 columns and I calculated the difference between the two columns. Now, If the difference is between a range of (-5 to +5), if should display something or if Difference greater than 5, it should display something and for rest i.e. difference < -5, should display something else.
I tried and came up with this
=IF("H2>5",<something1>, IF("H2<5",<something2>))
How to put the range part in this if-else ladder? Also the above If else is not giving value but the result is turning out to be #VALUE.
Thanks for your help.
Try
=IF(H2<-5,"Negative",IF(H2<=5,"In Range","Positive"))
There could be 3 possibilities only, 1 the answer is between -5 to 5 inculdining -5 and 5. 2 greater then 5. 3 smaller than -5. so this should work
=IF(AND(H2>=-5,H2<=5),"between -5 &5",IF(H2<-5,"Smaller than-5",IF(H2>5,"greater than 5 ")))
let me know if this is what is required.

IF function with 3 conditions

I'm looking to create a formula with 3 conditions. It is currently only working with 2 conditions. Here's what I'm looking for:
E9 has a number
If the number is 21+ then I want it to show Text 1
If the number is between 5 and 21, then I want it to show Text 2
If the number is below 5, then I want it to show Text 3
This is what I currently have:
=IF(E9>21,"Text 1",IF(E9<21,E9>5,"Text 2")
When I try and add the final condition, it gives me an error that I've entered too many arguments for this function. When the number is below 5 it shows False.
I would prefer a solution that does not use VLOOKUP.
I'm not understanding why it's saying this is not allowed, I have another IF function with 5 nested formulas that works just fine.
You can do it this way:
=IF(E9>21,"Text 1",IF(AND(E9>=5,E9<=21),"Test 2","Text 3"))
Note I assume you meant >= and <= here since your description skipped the values 5 and 21, but you can adjust these inequalities as needed.
Or you can do it this way:
=IF(E9>21,"Text 1",IF(E9<5,"Text 3","Text 2"))
Using INDEX and MATCH for binning. Easier to maintain if we have more bins.
=INDEX({"Text 1","Text 2","Text 3"},MATCH(A2,{0,5,21,100}))
=if([Logical Test 1],[Action 1],if([Logical Test 2],[Action 1],if([Logical Test 3],[Action 3],[Value if all logical tests return false])))
Replace the components in the square brackets as necessary.
You can simplify the 5 through 21 part:
=IF(E9>21,"Text1",IF(E9>4,"Text2","Text3"))

Resources