Getting Excel to select from one of three range options - excel

I'm trying to devise a dynamic spread sheet involving pension contribution percentages which increases with the age of the employees.
I've used the =now() function to calculate their ages on a dynamic basis and I now need to get excel to look at their age in cell H2 and apply the following criteria, altering automatically as their age increases into the next bracket:
if they are currently aged between 18 - 39 pension contribution is 6%
between 40 - 49 it is 7%
and over 50 it is 10%
The formula I've devised is picking up the correct percentages for those 39 & under and for those 50+ but I can't get it to recognize the 7% for those between 40 - 49.
Can anybody tell me where I'm going wrong?
=IF(H2>=OR18<=39,"6%",IF(H2>=OR40<=49,"7%",IF(H2>=OR50>100,"10%")))

Hi and welcome to Stack Overflow!
So assuming the value to test is in cell A1, the basic formula for matching within a range (say 1-10) is:
=IF(AND(A1 >= 1, A1 <= 10), "In Range", "Out of Range")
So expanding this to 3 ranges (18-39, 40-49, and 50+), and substituting your percentages, we get:
=IF(AND(A1 >= 18, A1 <= 39), "6%", IF(AND(A1 >= 40, A1 <= 49), "7%", IF(A1 >= 50, "10%")))
So a loose end that needs tying up is what to do if the age is less than 18 - currently this formula will produce FALSE. You might want to put something else in by adding a result for the second condition in the last test - so where the value doesn't match >= 50, e.g.
... IF(A1 >= 50, "10%", "NOT APPLICABLE") ...
or some other value that's appropriate.

Related

Simple(r) Excel formula to calculate forward stock (inventory) cover

This is a perennial question for retailers, for which there are a number of solutions in existence:
How can you calculate the "forward cover" of a product knowing its current inventory and armed with forward sales estimates.
eg.
current inventory 100 units (cell A1)
weekly forward sales estimates: 25, 30, 10, 40, 90... (in range
A2:AX)
Here the answer would be 3.875 weeks (3 full weeks plus 0.875 of week 4)
I have a UDF to do this already.
I also have some slightly complicated array functions to do this, eg.
=MATCH(TRUE,SUBTOTAL(9,OFFSET(A2:A13,,,ROW(A2:A13)-ROW(A2)+1))>A1,0)-1+(A1-SUM(A2:INDEX(A2:A13,MATCH(TRUE,SUBTOTAL(9,OFFSET(A2:A13,,,ROW(A2:A13)-ROW(A2)+1))>A1,0)-1)))/INDEX(A2:A13,MATCH(TRUE,SUBTOTAL(9,OFFSET(A2:A13,,,ROW(A2:A13)-ROW(A2)+1))>A1,0)-1+1)
I was wondering if there is a neater way with these 'new-fangled' array functions which have been available for the last few years in later versions of Excel?
Here is another possible solution, although it requires the LET() function which is only available to newer version of excel (2021, 365 and later I believe).
The solution would be the following formula:
=LET(
sales,A2:A50,
inventory,A1,
cum_sum,MMULT(SEQUENCE(1,ROWS(sales),1,0),(ROW(sales)<=TRANSPOSE(ROW(sales)))*sales),
week_full,MATCH(TRUE,inventory<cum_sum,0) - 1,
week_frac,(inventory - INDEX(cum_sum,week_full)) / INDEX(sales,week_full + 1),
week_full + week_frac
)
Explanation
Given inventory and the forward looking sales estimates, the formula calculates the running total (i.e. cumulated sum) of the sales estimates as shown in the table here below
Inv and Sales
Cumulated Sum
Inv > Cum_Sum
Week
100
25
25
0
1
30
55
0
2
10
65
0
3
40
105
1
4
90
195
1
5
...
...
1
6
The formula goes on to get the number of full weeks of 'forward cover' by finding the the value for the cumulated sum that exceeds the inventory minus one (here 4 - 1 = 3).
Lastly, for the value of the week fraction covered in the last week, the formula calculates inventory minus sum of sales estimates of all previous weeks divided by sales estimate of final week of cover (i.e. (100 - 65) / 40 = 0.875).
Edit
After simplifying the formula you used with the LET() function, I noticed it's doing exactly the same calculation with the only difference of how the cumulated sum is being calculated. Here's your formula using LET():
=LET(
sales,A2:A50,
inventory,A1,
cum_sum,SUBTOTAL(9,OFFSET(sales,,,SEQUENCE(ROWS(sales)))),
week_full,MATCH(TRUE,cum_sum>inventory,0)-1,
week_frac,(inventory - INDEX(cum_sum,week_full)) / INDEX(sales,week_full+1),
week_full + week_frac
)
=LET(inv,A1,
sales,A2:A6,
cs,SCAN(0,sales,LAMBDA(x,y,x+y)),
m,XMATCH(A1,cs,1)-1,
m+(inv-
IF(m=0,
0,
INDEX(cs,m)))
/INDEX(sales,m+1))
SCAN() is perfect for creating a cumulative sum.
It can be referenced inside XMATCH because of the use of LET.
Here m returns the number of full weeks and the final calculation is the number of full weeks + (inv- cumulative sum up to the full week)/sales of the following week.

Dynamic score within range based on value

I am attempting to score a record based on where it's value falls within a range. I know I can create a lookup table but that would be rather time intensive and was hoping for additional options.
Example:
Lower bound of 0
Upper bound of 90
Record has a score of 67
What I want to do is score that record between 1 - 3 based on where the value of 67 falls within the range of 10 - 90. So in this instance this record would score a 2.25, or the like.
Thank you in advance for your assistnace!
This is a simple linear equation
With 67 in A1, in A2 enter:
=A1*0.025+1
and then apply rounding.
The 0.025 comes from =(3-1)/(90-10)
The above chart shows the mapping of records between 10 and 90 into scores between 1 and 3.
Assuming the score is linear, the following formula should work
=Record/(UpperRange - Lower Range)*2+1
In the example you give, this would be: 67/(90-10)*2+1 and the result would be 2.675
If you want the scores to go from 1 to 3, in 0.25 increments, with a lower bound of 0, and upper of 90, then:
=ROUNDDOWN(SCORE/(90/8),0)*0.25+1
Which gives 2.25

Sum minimum of corresponding column values - limited to date range

I have a data set with four columns: Start Date, End Date, Scheduled Qty, and Actual Quantity:
Start Date End Date Scheduled Qty Actual Qty
04/13/15 04/17/15 35 19
04/20/15 04/24/15 35 42
04/27/15 05/01/15 35 41
05/04/15 05/08/15 35 41
I want to find the total actual, except when the actual exceeds the scheduled I want to used the scheduled number.
In an already answered question (Sum minimum of corresponding column values) I found an array formula that works to total the lesser values of each row for the Qty columns (quotes used to display the less than symbol):
=SUM(IF(C1:C4"<"D1:D4, C1:C4, D1:D4))
This gives me a total for my whole range, but now I'd like to limit it to a date range such as end dates within a given month. I've used SUMIFS in other situations to look at my end dates and only sum data that falls within a given month, but I'm not figuring out how to combine that idea with the one from the array formula.
Any ideas how to make this happen? I'm working in Excel 2013.
Here's an extension of chancea's approach:
Excel's SUM function (and AVERAGE, STDEV, etc.) have the useful behavior of "skipping" over text values. For example AVERAGE(3, 4, "dog", 5) returns 4. You can leverage this behavior nested IF's inside a sum. For instance,
=SUM(IF(MONTH(B1:B4)=4,IF(C1:C4<D1:D4,C1:C4,D1:D4),"NO"))
will sum
(a) the lesser of scheduled and actual
(b) when the month is 4
This is accomplished by nested IF's. The outer IF is
IF(MONTH(B1:B4)=4,...,"NO") [if month <> 4, IF returns text ("NO"), which SUM skips]
The inner IF is the same one that chancea showed.
You can nest as many tests/filters for your data as you need
To add criteria onto an array function most of the time you are just going to be multiplying the extra condition onto whatever set of conditions you already have.
The reason why this works is simply because we start with our list of numbers we want to sum:
IF(C1:C4<D1:D4, C1:C4, D1:D4) => { 19, 35, 35, 35 }
Then we multiply 1's or 0's to each of the values that meet the extra criteria.
So for an example lets say that we only want to check the quantity of values that have an end date within the month of 4. We can do that with:
MONTH(B1:B4)=4
Just multiply that criteria in the SUM function to basically create a boolean and condition for that criteria:
=SUM(IF(C1:C4<D1:D4, C1:C4, D1:D4)*(MONTH(B1:B4)=4))
= SUM({ 19, 35, 35, 35 } * { 1, 1, 0, 0}) => SUM( {19, 35, 0, 0} ) = 54
This is the same if we want to add n condition's:
=SUM(IF(C1:C4<D1:D4, C1:C4, D1:D4)*(MONTH(B1:B4)=4)*(`Condition2`)*(`Condition3`)...)
You can use any formula or operator that returns a true/false value within your conditions.
Such as: = > < >= <= <> IF(...,TRUE)
To add OR logic as a criteria you need to use addition instead of multiplication and then group them inside a (..)>0 like this:
(((Or_Condition1)+(Or_condition2)+...+(Or_conditionN))>0)
So if we wanted to sum months 4 OR 5 we can write:
=SUM(IF(C1:C4<D1:D4, C1:C4, D1:D4)*(((MONTH(B1:B4)=4)+(MONTH(B1:B4)=5))>0))

Errors when nesting IF() formulas

I'm just putting together a simple spreadsheet that calculates tax owed based on a few different bands. I have an 'Invoiced Amount' cell that takes up the yearly invoicing and then applies a tax rate to it based on the following conditions:
If 'Invoiced Amount' is below 10, 600 then Tax Owed = 0
If 'Invoiced Amount' is above 10, 600 but less than 42, 386 then Tax Owed = ((Invoiced Amount - Tax Allowance)/100) * 20
If 'Invoiced Amount' is Equal to or greater than 42, 386 than Tax Owed = ((42, 386 - Tax Allowance)*20)+((InvoicedAmount - 42, 386)*40)
I could be overlooking something really basic here, but just to be sure - Tax Allowance is 10, 600 - Anything over this up to 42, 386 is worked out at 20% tax, and then anything earn above 42, 386 is charged # 40% on top...
The more I type this out the more confused I am. Anyway, Here is my excel formula:
InvoicedTotal = P5
TaxAllowance (10600) ='UK Tax Figures'!C3
TaxAllowanceUpperBand (42386) ='UK Tax Figures'!G5
TaxAllowance Upper Band - Tax Allowance (31784) = H5
UpperTaxAllownace Band (42386.01) = ='UK Tax Figures'!F5
=IF ((P5)<’UK Tax Figures’!C3, 0, IF(P5>=’UK Tax Figures’!C3<'UK Tax Figures'!G5, ((P5-'UK Tax Figures'!C3)/100)*20, IF(P5>='UK Tax Figures'!F5, ((H5/100)*20)+((P5-'UK Tax Figures'!F5)*40))
At the moment I'm getting crazy unexpected values back, so the calculation is obviously VERY wrong... But I can't see the wood for the trees at the moment, so if anyone has any thoughts I would really appreciate it! Going a little crazy here at the moment!
Putting your formula into the Online Excel Formula beautifier I notice several problems with your formula:
=IF ( ( P5 ) < ’UK Tax Figures’!C3 , 0 ,
IF(
P5 >= ’UK Tax Figures’!C3 < UKTaxFigures!G5,
( ( P5 - UKTaxFigures!C3 ) / 100 ) * 20,
IF(
P5 >= UKTaxFigures!F5,
( ( H5 / 100 ) * 20 ) + ( ( P5 - UKTaxFigures!F5 ) * 40 )
)
First of all, you lack two closing parantheses
Furthermore, you have an invalid conditional in P5>=’UK Tax Figures’!C3<'UK Tax Figures'!G5, you need to change this to AND(P5>=UKTaxFigures!C3;UKTaxFigures!C3<UKTaxFigures!G5).
Taking a look at how you reference your worksheets above, I notice that it seems you have two different sheets - one with spaces between the words in the sheet names, and one without. I suspect this is not the case, so you should probably remove those spaces from the formula.
You are also inconsistent with whether or not you use apostrophes (’) around your sheet-names. Trying out your formula in a cell, Excel didn't seem to like them, so they should probably go as well.
there seems to be a return-value missing from your innermost if-statement if it is false.
Guessing a bit at what you want the formula to return, I end up with this formula:
=IF(P5<UKTaxFigures!C3;0;IF(AND(P5>=UKTaxFigures!C3;UKTaxFigures!C3<UKTaxFigures!G5);((P5-UKTaxFigures!C3)/100)*20;IF(P5>=UKTaxFigures!F5;((H5/100)*20)+((P5-UKTaxFigures!F5)*40);0)))
Which looks like this in the beautifier:
=IF(
P5 < UKTaxFigures!C3;
0;
IF(
AND(
P5 >= UKTaxFigures!C3;
UKTaxFigures!C3 < UKTaxFigures!G5
);
( ( P5 - UKTaxFigures!C3 ) / 100 ) * 20;
IF(
P5 >= UKTaxFigures!F5;
( ( H5 / 100 ) * 20 ) + ( ( P5 - UKTaxFigures!F5 ) * 40 );
0
)
)
)
Is that something close to what you want?
As a final word of advice it is an absolute pain to write a formula like that - instead you can try to build it bit by bit, storing each part of the formula in one cell to see if each of them works. Then you can cut and paste so that they all fit in one cell. I.e. if you in cell A1 store:
=IF(P5>=UKTaxFigures!F5;((H5/100)*20)+((P5-UKTaxFigures!F5)*40);0)
Then you can put
=IF(AND(P5>=UKTaxFigures!C3;UKTaxFigures!C3<UKTaxFigures!G5);((P5-UKTaxFigures!C3)/100)*20;A1)
in A2 and this
=IF(P5<UKTaxFigures!C3;0;A2)
in A3. If necessary you can pick the formulas even further apart to make them more readable. Then in the end you just copy the formulas from the cells, and replace the references with them.
Please note that I am not 100 % certain that I got everything correct, without proper data it is somewhat difficult to keep track of all the parantheses and results. But this should at least give you a good starting point.

Using If,Then function in Excel

I have a retail store that sells items on consignment for a fee that varies based on Selling Price.
So my question is how do I write a formula that checks the selling price and then charges the correct consignment fee to calculate the net based on the following schedule:
When selling price is over $400 then charge = 20%
When Selling price is $100 to $400 then charge = 30%
When Selling price is under $100 then charge = 40%
BLUF: use nested IF statements (an IF inside an IF) --
Example:
=IF(A2>=400, (A2*0.2), (IF(400 > A2 >= 100, (A2 *0.3), (A2*0.4))))
Or use the below if you suspect someone will foolishly enter a negative number or something nonsensical:
=IF(A2>=400, (A2*0.2), (IF(400 > A2 >= 100, (A2 *0.3), (IF(A2 < 100, (A2*0.4), (0))))))
That may look complex, but let's break it down from the beginning.
The basic formula for the IF statement:
=IF(testCondition, (resultIfTrue), (resultIfFalse))
One IF statement will only allow you to do two of your 3 conditions:
=IF(A1 > 400, (A1 * .20), (A1 * .30))
The above basically says that if the number in cell A1 is greater than 400, then the value in your current cell (e.g. B2) is A1 * 20%. But if the number in A1 is NOT greater than 400, the value in your cell will be A1 * 30%.
But how do we calculate the range you were asking (i.e. 100 - 400) and how do we add in a third possibility (i.e. the possibility that the number is less than 100)?
The answer is to use a nested IF. You can tell the cell what it's value should be if the condition is true, but you can test another condition if the answer is false (i.e. the next IF statement stands in the place of resultIfFalse.
=IF(testCondition, (resultIfTrue), (IF(testCondition, (resultIfTrue), (resultIfFalse))))
The above can handle 3 different scenarios. Out of the IFs above, you could also replace the second IFs resultIfFalse with yet another IF statement, and so on. You can nest up to 64 IF statements.
Extra Resources:
http://fiveminutelessons.com/learn-microsoft-excel/using-multiple-if-statements-excel
http://spreadsheets.about.com/od/tipsandfaqs/qt/nested_if.htm
Nested IF functions are not user friendly and require hardcoding your variables (percentages). My suggestion would always be to have a small table of values elsewhere: eg. put the following in A1:B3
0 0.4
100 0.3
401 0.2
Assuming your data is in D1 you can use the following formula in E1 and drag down if necessary
=INDEX($B$1:$B$3,MATCH($D1,$A$1:$A$3,1))
This way you can change your boundaries/ add more conditions easily without more nested IF statements
Try using this instead:
=IF(B1<100,B1*40%,IF((B1>=100)*AND(B1<=400),B1*30%,IF(B1>100,B1*20%,"Invalid Price"))
This formula contains nested-ifs and a logical AND condition which will give the result.

Resources