Excel: alternative to long IF statement - excel

Trying to calculate the total amount based on different discount factors throughout the term. For example, if a base price is $1,000/month, that will be for months 1 – 24, then $500/month 25-48 and $250/month 49 and after. I think I can do this with IF statements but is there a better way to compute this calculation in Excel?
=IF(B2<=$E$2,A2*B2,IF(AND(B2>=$D$3,B2<=$E$3),(24*A2*$F$2)+(B2-$E$2)*(A2*$F$3),IF(B2>=D4,(24*A2*F2)+(24*A2*$F$3)+(B2-48)*(A2*F4))))

Change your table as shown below, and use the following formula:
=A2*VLOOKUP(B2,$D$2:$F$4,2)+A2*(B2-VLOOKUP(B2,$D$2:$F$4,1))*VLOOKUP(B2,$D$2:$F$4,3)
There is no test done for maximum months. You can add that as an IF if necessary.
This method allows for a lot of flexibility in altering the terms. It is also useful in calculating things like income taxes and other stuff for which there is this kind of "tiering"
EDIT: The formula for the Base column:
E2: 0
E3: =E2+(D3-D2)*F2
and fill down from E3 to the bottom of the table

Related

How can I determine the 'total cost' from a tiered pricing structure using standard formulas in Excel?

I'm trying to evaluate various tiered pricing structures (for say, electricity plans) using Excel (more-or-less) to see what costing/plan is 'optimal', given some existing usage data I have.
Consider an example 'Table of Usage & Rates' (with fictitious but easily manipulated values):-
For a daily usage value of 120, we'd have 100 (in the 1st tier) and 20 (in the 2nd tier). The amount used within a tier gets charged at a certain rate (the 'factor')... and each 'tier charge' is addded together to form a total charge for the day.
So, we can calculate:-
100 x 8 = 800 ...a part of the total
20 x 4 = 80 ...another part of the total
...and that's all, giving a total of 880.
...but how to do that in a single formula within a cell?
I've done some pretty decent explorations for a few hours today, as I can't nut out how to deal with this... and most suggestions talk about multiple =IF formulas (cumbersome and unscalable - I shouldn't need to recode cell contents if I split/add another tier)... and suggestions with =VLOOKUP just don't 'click' with me ( = I don't understand them).
I'm actually using 'PlanMaker', a component of Softmaker's 'Office 2021' product to create/maintain this spreadsheet.. and there is no VBA-like plugin available.
I'd appreciate a method of attack, if anyone can suggest something, please...
So:
=product(10,8)+product(20,4)
or if we assume Factor starts in B9 then =product(A9,B9)+product(A10,B10+product(A11,B11)
then take the sum of those results etc assuming A9 is the amount used.
You can also use:
=sumproduct(A9:A11,B9:B11)
for the same but only needs one cell. And the advantage of a lot less typing.
You can include a 3rd array in sumproduct (or as many as needed) such as a binary value to include in the calculation or not.

In Excel, "if greater than 0 and less then 10 then "x", but if greater then 10 and less then 20 then "y" in same cell

I am trying to create a formula to calculate shipping based on price but I have only been able to find this:
=IF(AND(D2>0.01,D2<13.51),4.51,"")
Basically it reads "If the total purchase (D2) is greater then $0.01 and less then $13.51 apply $4.51 as the shipping fee. This works for the one fee but I need it to apply the other fees as well and I cannot seem to figure out how to do multiple greater than, less than in one formula.
So I need to be able to add multiple of that same code and change the numbers, but I can't figure out how to do multiple without getting an error.
VLOOKUP with approximate match sounds like it would be the easiest if you have a lot of shipping prices. The lookup table is in grey and you can setup however you like. If column 'B', put the formula =VLOOKUP(A2,$D$2:$E$5,2,TRUE) The TRUE is was provides the approximate match.
A nested IF would work, but would be horrible to manage. Using the VLOOKUP, anyone could maintain the lookup table.

Excel Formula IF(AND #VALUE! Error

I am working on a financial model in excel. If the number of customers is between 1-10000, the cost is .20 per customer per month, 10000-100000 is .15 per customer per month, 100k and 1MIL is .10 per customer per month and > 1MIL is .08 per month per customer.
What I would like to do is create a formula where if the cell that references the number of customers at that month is within those values above, the cost per month changes depending on the number of cstomers.
This is what I have:
=IF(AND(B6>=1,B6<=10000),$Q$6), IF(AND(B6>10000,B6<=100000),$Q$7), IF(AND(B6>100000,B6<=1000000),$Q$8),IF(AND(B6>1000000),$Q$9)
Q6, Q7, Q8, Q9 are respectively: $.20, $.15, $.10, $.08
My B6 cell is the cell that is pulling over the number of customers from another sheet.
I am getting a #VALUE! Error when I use this formula. It works if I simply have:
=IF(AND(B6>=1,B6<=10000),$Q$6) which leads me to believe that my logic is wrong with all of the IF statements, and I should be using ELSEIF but I am not sure the syntax for that.
Help is appreciated!
So this is how I fixed this issue in case anyone had the same issue:
=IF(B6<=10000,$Q$6,IF(B6<=100000,$Q$7,IF(B6<1000000,$Q$7)))
By nesting the if statements with higher values excel automatically recognizes the max value for that if statement!
It seems that you are closing the IF statements too soon. Your formula repaired would look like,
=IF(AND(B6>=1,B6<=10000),$Q$6, IF(AND(B6>10000,B6<=100000), $Q$7, IF(AND(B6>100000,B6<=1000000), $Q$8, IF(AND(B6>1000000),$Q$9))))
If you start at the upper limit, you can reduce the conditions with sequential logic.
=IF(B6>1000000,$Q$9, IF(B6>100000, $Q$8, IF(B6>10000, $Q$7, IF(B6>=1,$Q$6, 0))))
You could probably do that a little more easily like this
=IF(B6>1000000,$Q$9,IF(B6>100000,$Q$8,IF(B6>10000,$Q$7,IF(B6>=1,$Q$6,"Error))))
You don't need AND because the IF functions are implicitly checking a range because the previous IFs rule out ranges of values

Calculating Percent of Total in Power Pivot Model

I have created a power pivot table as shown in the picture. I want to calculate quarter over quarter sales change. For which I have to divide for example corporate family "Acer" 's sales in 2012Q4 by sum of all the corporate family. I am using calculated measure to do this, but I am not sure what formula I can use.
My need is to create two columns, one for 2012Q4 percent of total and one for 2013Q1 percent of total. Then I will create another measure to find the difference. So the formula for 2012Q4 should be like this 1624442 / (1624442+22449+1200+16123) . Any idea which function can help me do it?
It sounds like you are measuring the change in the percent of total for each corporate family from quarter to quarter. You will need to create 3 calculated measures. I'm not sure what your model looks like so I can't give you the exact formula, but here is the idea.
CurrentQtr%ofTotal:= Divide(Sum('Sales'[Units]),Calculate(Sum('Sales'[Units]), All['Product'[Corporate Family])))
PrevQtr%ofTotal:= DIVIDE(CALCULATE(Sum('Sales'[Units]), DATEADD(DimDate[DateKey], -1, QUARTER)),
CALCULATE(Sum('Sales'[Units]), DATEADD(DimDate[DateKey], -1, QUARTER), All('Product'[Corporate Family]))))
Change%ofTotal:= DIVIDE(([CurrentQtr%ofTotal]-[PrevQtr%ofTotal]),[PrevQtr%ofTotal])
I used the divide function because it handles divide by zero errors. You use the ALL function to remove the filter on the Corporate Family column from the filter context. The Change%ofTotal is just to find the differenc. I'm calculating % change but you may just want to subtract.
Here's the link to a good blog post on time intelligence. And here's one on calculating percent of total.
For percentages please follow the tutorial on the Tech on the Net.
Adding another column where you calculate a difference between two pivot columns will not work - this column is "unpivotable", as it relies on a column defintion. You would need to copy and paste pivot as values to another worksheet and do the extra calculation there.

Excel what method use to calculate time and age

I have got a table with 2 columns:
AGE between 10 and 90 lets say :]
and Time (spent on mobiles)
What I need to do is- count how long people spent time on mobiles between 16 and 40.
First part may be seemingly simple because we can count by countif how may people is using mobiles between 16 and 40 but how evaluate spend time on mobiles by the particular age groups.
I will appreciate aaany help
regards
If you need to analyze your data more than creating a static function to count, you may consider using Pivot tables.
Build a simple pivot table with age in rows and time in values. Once this simple pivot table built, you can filter on the rows values, group them together among specific grouping criteria, select specific values by hand, etc.
I like the idea given by Boud of using Pivots but if you specifically want a formula then you can use SumProduct()
=SUMPRODUCT((A2:A13>16)*(A2:A13<40)*(B2:B13))
Do remember to format the cell as [h]:mm:ss since you are adding up times.
SNAPSHOT
You can for example add additional column, with formula like:
=IF ( AND(A1>16, A1<40), B1, 0 )
where A is column with AGE, and B is column with Time, and then simply sum it!

Resources