if statement in microsoft excel - 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

Related

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

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.

Nested IF Statement (price bands)

I am trying to create a formula using the following parameters:
=IF(E20<=500,E20*.90,IF(E20<=1000,E20*.80,IF(E20<5000,E20*.70,IF(E20<=10000,E20*.60,IF(E20<999999,E20*.50
I want the formula to calculate the price if the quantity falls within the range but am missing something with the formula above.
Could someone please point out the mistake and offer a suggestion or correction?
Since struggling with nested IFs (understandably!) you might be better off with a lookup table. Say name an array as below LT;
1 0.9
500 0.8
1000 0.7
5000 0.6
10000 0.5
and apply =VLOOKUP(E20,LT,2)*E20
With this, you check if cell A1 value falls between 100 and 200
=IF(A1 < 200; IF(A1 > 100; "ok"; "no"); "no")
Instead of "ok", you can insert your price calculation.
With this, you check if A1 < 100, if it is not then it checks if A1 < 200, and again if not it checks if A1 < 1000. If none of these conditions are true, it says "A1 > 1000"
=IF(A1 < 100; "A1<100"; IF(A1 < 200; "A1 < 200"; IF(A1 < 1000; "A1 < 1000"; "A1 > 1000")))
Again, instead of the optut string, you can insert your price calculation
Hope it helps, regards

using excel divide any value in a col by 1000, then multp new value by 10 & upd a running total cell, while leaving the orig value alone

For example if I enter a 2000 in B3, I would like that number divided by 1000, then multiplied by 10, and have the new value added to a running total. ie (2000/1000 * 10=20)
RunningTotal = 20
For clarity, if I enter 8000 in B4, then I would like to (8000/1000 * 10 = 80 )
RunningTotal = 100
Notice that
(x / 1000 * 10) + (y / 1000 * 10) = (x + y)/1000 * 10
So the equation for your running total cell only needs to be:
=SUM(B3:B10)/1000*10
Assuming B3:B10 is the appropriate range for your inputs.
equation formula
(x / 1000 * 10) + (y / 1000 * 10) = (x + y)/1000 * 10
=
(x+y) * 0.01
=
sum(B3:B?) * 0.01
You can simply record a macro:
http://office.microsoft.com/en-us/excel-help/create-a-macro-HP005204711.aspx
So you do everything you would like to calculate "by hand" while recording a macro and then you can call it at any time you want to execute.
Thanks for the replies.
I will be entering in values into col B(B3,B4...B200 etc.). The running total value will be displayed in it's own cell. The running total value will be updated upon save or enter. The orig value entered into the B column cells should remain the same.
The formula or calculation should occur anytime a value is entered into a cell within col B.
So if I have any number of values in col B, what I am expecting is:
1000/1000 * 10 = 10
5000/1000 * 10 = 60
8000/1000 * 10 = 140 etc.
If I use a separate cell to hold the runningTotal value, for ex K2...formula is: =C3/1000*10 ...how can I repeat this formula for subsequent cells in col B, but update the cell K2?
Must I use a holding column for each corresponding value entered in col B, then add the value to the K2 cell?
Ah, yes, I have managed to get it working by using a holding cell. if there is a more elegant approach, I am open to suggestions.
thanks for your advice.

How do I create a formula for "if x ≥ then multiply by y" and so on?

I've only used Excel for the basics.
I want to multiply the contents of the cell by a different number depending on the value in the cell. I have these ranges:
0 - 499, then multiply by 0
500 - 999, then multiply by 1
1000 - 1499, then multiply by 4
I was able to figure out the formula =IF(C21>=10000,C21*1) for if a value in cell C21 is greater than or equal to 10,000, but I don't see how to extend that to multiple ranges.
How can I write a formula to handle the multiple ranges I've listed above?
You can use another IF in the ELSE part of the expression, evaluation will stop as soon as a TRUE condition is met;
=A1 * IF(A1 < 500, 0, IF(A1 < 1000, 1, IF(A1 < 1500, 4, 0)))
(The last 0 is the case when the value is > 1499)
You can use nested IF statements for doing ranges:
=IF(C21>=500,IF(C21>=1000,IF(C21<1500,C21*4,'dontknowwhatyouwanthere'),C21*1),0)
How about nested Ifs?
=IF(A1<1000;IF(A1<500;+A1*0;+A1*1);+A1*4)
Then you've got:
If it's less than 1000 another if:
If it's less than 500 You do the " * 0 "
If it's not (you are at 500-999 range, from the first if) You do the " * 1 "
Else it's not less than 1000:
You have your " * 4 "
I used this formula and it worked:
=V4*IF(V4<600,0.2,IF(V4<800,0.22,IF(V4<1000,0.25,IF(V4<10000,0.27))))

Resources