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

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

Related

Excel Solver / Linear Programming: How to set constraint enforcing the maximum 'distance' between high vs low decision variables?

Suppose I have a set of binary decision variables (e.g. an 1 row array of 10 price points from $1, $2, ..., $10).
The optimization itself is not important, except I must choose no more than 4 price points. That constraint is solved, sum up the binaries and constrain the sum to be <= 4.
Another constraint is required, however, which is stumping me. I need to create a constraint where the highest and lowest price points of whatever was chosen is no greater than a value I enter in a cell. Suppose I enter "4" in the cell, then all of the price points must be within $4 of each other (e.g. $1 cannot be chosen with $6 or higher, $5 is OK).
Example: Maximum Price Distance = $5 (this is a variable cell)
DV: [1, 0, 1, 1, 1, 0, 0, 0, 0, 0] is OK
DV: [1, 0, 1, 0, 0, 0, 0, 0, 1, 0] is NOT OK
How do I do this in a way that is linear (cannot use MAX(), MIN(), or IF() functions)?
Something like
Maxprice >= x(i) * price(i)
Minprice <= x(i) * price(i)+(1-x(i))*M
Maxprice - minprice <= maxdifference
Where M is a constant M=max(i,price(i)).

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

How to add up an arbitrary number of cells

I have a spreadsheet in which for each column/category, I tally up the the values for the last X days from another sheet.
This X is different for different columns/categories.
Here is the equation that I am currently suing, which tallies up to a week's worth of values, depending on the value of D$2 (the number of days that I want to tally). (Equation has been formatted to make it easier for humans to read):
= Daily!D15
+ IF(D$2 >= 2, Daily!D14, 0)
+ IF(D$2 >= 3, Daily!D13, 0)
+ IF(D$2 >= 4, Daily!D12, 0)
+ IF(D$2 >= 5, Daily!D11, 0)
+ IF(D$2 >= 6, Daily!D10, 0)
+ IF(D$2 >= 7, Daily!D9 , 0)
This works fine, as long as I only want to tally up anywhere from 1-7 days. But I would like to upgrade this spreadsheet so that it can tally an arbitrary number of of days without having to modify the equation. I'd like to be able to be able to tally, for example, 100 days without
having to create an equation with 99 IF statements in it.
Offset is really handy. It returns a range of cells relative to a given reference. In your example you'd use:
=SUM(OFFSET(Daily!D15,0,0,-D$2,1))
To explain: Starting with the reference Daily!D15, we shift 0 rows and 0 columns, then select a range with D$2 rows and 1 column. Since -D$2 is negative, the range is expanded upward, rather than downward.
The last two arguments ('height' and 'width') are optional -- if left out, the range returned will have the same dimensions as the range we provided. In fact, in this case we could have used =SUM(OFFSET(Daily!D15,0,0,-D$2)), and the width of 1 column would have been implied by the width of Daily!D15. For readability, though, I like to include both dimensions or neither.

Excel Formula to SUMIF date falls in particular month

I have excel data in following format.
Date Amount
03-Jan-13 430.00
25-Jan-13 96.00
10-Jan-13 440.00
28-Feb-13 72.10
28-Feb-13 72.30
I need to sum the amount field only if the month lies in Jan Month.
What i have tried is ,
=SUMIF(A2:A6,"MONTH(A2:A6)=1",B2:B6)
But it returns,
0
What i need is,
Following values to be summed, 430.00 + 96.00 + 440.00 = 966.00
Try this instead:
=SUM(IF(MONTH($A$2:$A$6)=1,$B$2:$B$6,0))
It's an array formula, so you will need to enter it with the Control-Shift-Enter key combination.
Here's how the formula works.
MONTH($A$2:$A$6) creates an array of numeric values of the month for the dates in A2:A6, that is, {1, 1, 1, 2, 2}.
Then the comparison {1, 1, 1, 2, 2}= 1 produces the array {TRUE, TRUE, TRUE, FALSE, FALSE}, which comprises the condition for the IF statement.
The IF statement then returns an array of values, with {430, 96, 400.. for the values of the sum ranges where the month value equals 1 and ..0,0} where the month value does not equal 1.
That array {430, 96, 400, 0, 0} is then summed to get the answer you are looking for.
This is essentially equivalent to what the SUMIF and SUMIFs functions do. However, neither of those functions support the kind of calculation you tried to include in the conditional.
It's also possible to drop the IF completely. Since TRUE and FALSE can also be treated as 1 and 0, this formula--=SUM((MONTH($A$2:$A$6)=1)*$B$2:$B$6)--also works.
Heads up: This does not work in Google Spreadsheets
=Sumifs(B:B,A:A,">=1/1/2013",A:A,"<=1/31/2013")
The beauty of this formula is you can add more data to columns A and B and it will just recalculate.
=SUMPRODUCT( (MONTH($A$2:$A$6)=1) * ($B$2:$B$6) )
Explanation:
(MONTH($A$2:$A$6)=1) creates an array of 1 and 0, it's 1 when the
month is january, thus in your example the returned array would be [1, 1, 1, 0, 0]
SUMPRODUCT first multiplies each value of the array created in the above step with values of the array ($B$2:$B$6), then it sums them. Hence in
your example it does this: (1 * 430) + (1 * 96) + (1 * 440) + (0 * 72.10) + (0 * 72.30)
This works also in OpenOffice and Google Spreadsheets

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