Prorating formula based on weeks, months

Lil Stinker

Board Regular
Joined
Feb 16, 2022
Messages
151
Office Version
  1. 2019
Platform
  1. Windows
The formula I have in the Subtotal column below doesn't quite work for what I need. What I'm looking for is when a user selects "Months" from the drop down in cell E1, I need the formula to begin prorating after a 30-day minimum period. I also need it to prorate when the user selects "Weeks", to start prorating after a 7-day minimum. This way, if they are taking equipment out for any period of time less than the required one month or one week minimum, the rate does not start prorating immediately.

What I currently have for the weekly IF formula sort of works but the math is off. As you can see in the example, $200*2*1.71 should equal $684 and $100*1.71 should equal $171 but somehow it is adding change from somewhere. The totals come out correct only when the period of time is an even number like 1 week or 2 weeks.

I'm pretty inept at putting together Excel formulas... please help!

ORDER FORM -formula tests- 2022.xlsx
ABCDEFGHIJKLM
1DescriptionQTYUnit RateWeeksItem Subtotal[ Term ]
2Pickup DateMiFi Hotspot2200.001.71$685.72Months
312/29/22MiFi Hotspot1100.001.71$171.43Weeks
4Billing Start
502/24/22
6Billing EndMonthsWeeksDaysWeekly RateDaily RateSubtotal
703/08/220.001.005.0050.007.14171.40
8Return Date0.001.005.0025.003.5742.85
904/01/22      
10      
11Subtotal$857.15      
12Discount$0.00      
13Net Amount$857.15      
14TOTAL AMOUNT$857.15      
Sheet2
Cell Formulas
RangeFormula
E2:E3E2=IF(E$1="Weeks",ROUNDDOWN((DATEDIF($A$5,$A$7,"d")/7),2),IF(OR($B2="",AND(E$1<>"Months")),"",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(E$1="Months",DATEDIF($A$5,$A$7,"m")&"m,"&INT(($A$7-EDATE($A$5,DATEDIF($A$5,$A$7,"m")))/7)&"w,"&MOD($A$7-EDATE($A$5,DATEDIF($A$5,$A$7,"m")),7)&"d",INT(($A$7-$A$5)/7)&"w,"&MOD($A$7-$A$5,7)&"d"),"0m,",""),"0w,",""),",0d","")))
F2F2=IF(ISBLANK(C2),"",IF(E$1="Months",(D2*H7+K7*I7+L7*J7)*C2,IF(E$1="Weeks",ROUNDUP((MAX(D2,DATEDIF($A5,$A7,"d")*D2/7)*C2),2))))
F3F3=IF(ISBLANK(C3),"",IF(E$1="Months",(D3*H8+K8*I8+L8*J8)*C3,IF(E$1="Weeks",ROUNDUP((MAX(D3,DATEDIF($A5,$A7,"d")*D3/7)*C3),2))))
H7:H14H7=IF(ISBLANK(C2),"",DATEDIF($A$5,$A$7,"M"))
I7:I14I7=IF(ISBLANK(C2),"",INT(($A$7-EDATE($A$5,DATEDIF($A$5,$A$7,"m")))/7))
J7:J14J7=IF(ISBLANK(C2),"",MOD($A$7-EDATE($A$5,DATEDIF($A$5,$A$7,"m")),7))
K7:K14K7=IF(ISBLANK(C2),"",(ROUND(D2/4,2)))
L7:L14L7=IF(ISBLANK(C2),"",(ROUND(K7/7,2)))
M7:M14M7=IF(ISBLANK(C2),"",(D2*H7+K7*I7+L7*J7)*C2)
F11F11=SUBTOTAL(109,Table22[Item Subtotal])
F13F13=(F11-(F11*F12))
F14F14=F13
Cells with Data Validation
CellAllowCriteria
E1List=$H$1:$H$3
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
$200*2*1.71 should equal $684 and $100*1.71 should equal $171 but somehow it is adding change from somewhere.
Your formula in F2 is not using E2. It's calculating the period as 12 days/7 = 1.714 ... weeks , without rounding to 1.71 as the formula in E2 does.
 
Upvote 0
Thanks, but I haven’t been able to get the formula from E2 in part or in full to work properly in F2. And, I still don’t know how to lock in the minimum rate for the monthly formula or the weekly formula and then start prorating only after the minimum.

The monthly formula is especially confusing because there are multiple formulas used in calculating the correct proration. The table in H-L is how I break out the monthly proration but how can I lock in the 30-day minimum when calculating the subtotal? And wrap it all up in one tidy formula that covers all the bases when you pick monthly or weekly from the drop down?
 
Upvote 0
It's not totally clear what you're trying to do, but it looks like you're over-complicating it ...

If you're charging by the month/week/day, it makes sense to split the hire period into months, weeks and days as you have done.

I can see you got your formula in E2 from this post: Help with Month, Week, Daily formula. The reason this formula is so complicated is that it duplicates the calculations that you're already doing separately in your months/weeks/days table. You can concatenate these intermediate results rather than re-calculating them.

It's only a guess, but I think you're saying that if someone chooses to hire:

- by the month, the minimum charge is one monthly fee, and thereafter the monthly fee for whole months, and the daily fee/30 for part months?
- by the week, the minimum charge is one weekly fee, and thereafter the weekly fee/7 for part weeks?

But that's not what your formula is doing, e.g. if someone hires on a monthly basis from 1 March to 30 March, your formula will charge for 4w, 1d. (And it also incorrectly charges 4.14 times the monthly fee, rather than the weekly fee!) Note that the solutions provided in the above post take your formula as a given starting point.

If my interpretation is correct, can you please provide a few examples along the following lines. We'll need to understand exactly how you want to calculate months, e.g. hire date 31 December 2021, return date 28 February 2022. Is this two whole months? Or 1m, 28d? Please also let us know what intermediate rounding you want to use, e.g. it looks like 1w, 1d should be taken as 1.14 weeks, i.e. rounded to 2dp. What about 1m, 1d? Is this 1.03 months?

ABCDEFG
1MonthlyRate$200
2WeeklyRate$50
3
4HireReturnTypeMonthsWeeksDaysFee
51 Jan 20223 Jan 2022Weekly1$50.00
61 Jan 202216 Jan 2022Weekly21$107.14
71 Jan 202216 Jan 2022Monthly1$200.00
81 Jan 202216 Feb 2022Monthly115$300.00
9etc?
Sheet1
Cell Formulas
RangeFormula
G5:G8G5=D5*MonthlyRate+E5*WeeklyRate+F5*IF(C5="Weekly",WeeklyRate/7,MonthlyRate/30)
Named Ranges
NameRefers ToCells
MonthlyRate=Sheet1!$B$1G5:G8
WeeklyRate=Sheet1!$B$2G5:G8
 
Upvote 0
You're not far off. It's actually equipment rental. I'm trying to design a better quoting system using Excel for users who don't use Excel at all. Trying to keep it simple for them unfortunately means all sorts of complications for me as the designer, I'm finding out. So, the client puts in a request for equipment, our sales people would use this form to provide the client with a quote for the rental.

Whether a client is on a Monthly rental vs Weekly rental is determined by the salesperson and the duration of time they plan to have the equipment out. This is why I give them a drop down to choose the rental duration as opposed to having two separate forms for monthly or weekly. Typically, if someone has equipment out anywhere under three weeks, they will go on a weekly rate. If they plan to have the equipment out longer than that, it would be more cost effective to put them on a monthly rental. It's not an automatic calculation which is why the salesperson needs the option. Some rentals necessitate a monthly rental even if the equipment is only out for two weeks. It's discretionary.

- How we calculate a monthly rental is: one month minimum/4 for the weekly cost/7 for the daily cost. If the rate is $200 per month and the rental period is 1m, 2w, 1d, as in your Row 8 example, it would calculate like 200+(50x2)+(7.14x1)=$307.14, not $300. It's not broken down by the day after the monthly minimum. But your example in Row 7 is correct if they have the equipment out for any period of time less than a month and they are on a monthly rental rate, their cost is the one month minimum.

- How we calculate a weekly rental is the same as your example: one week minimum/7 for the daily cost. So, a $100 per week rental for 1w, 5d would be 100+(14.29x5)=$171.45. But if they're quoted a weekly rate and they only take the equipment out for 2 days, the formula needs to lock in the weekly minimum rate. Whatever that rate is, is determined by the salesperson. In this example, $100. So your weekly examples in Rows 5 & 6 are correct as well.

The problem is our rates vary so I can't really lock them in a Named Range as you have done. Also because the rate varies based on each piece of equipment and the rental term. I've got a long product database on a separate sheet using a VLOOKUP formula to produce the unit rates for Column D.

Your sample set seems to work for the most part as long as it can be adjusted to calculate the monthly rate by first the month, then the week, then the day. Then it just needs to fit into my table format and operate with the data validation drop down in E1.
 
Upvote 0
I've now got this working the way I'd like in terms of prorating monthly and weekly rates correctly. Now, I just need to fix in a minimum rate in the calculation formulas for both the monthly and weekly rental terms. Meaning, if a weekly rental is chosen but the duration is less than 7 days, it should still total the weekly rate in column D rather than breaking it down by the day. Same for when a monthly rental is chosen on the form, if the duration is less than a month, it should still total the monthly rate in column D.

I'm sure I could use an IF statement to do this but how do I get it to actively change based on choosing Weeks or Months from the drop down in E17 & E32? And, in what cells would I need the IF to go?

Below are two samples of the same form indicating a monthly term and a weekly term just to display the different result. It's really meant to be just one form.

ORDER FORM -formula tests- 2022.xlsx
ABCDEFGHIJKLMNOPQRS
17DescriptionQTYUnit RateMonthsItem Subtotal[ Term ]MonthsWeeksDaysWeekly RateDaily RateSubtotalWeeksDaysDaily RateSubtotal
18Computer Monitor1200.004w,1d$207.14Months0.004.001.0050.007.14207.144.001.0028.57828.57
19Speaker Set250.004w,1d$103.58Weeks0.004.001.0012.501.79103.584.001.007.14414.28
20Start DateKeyboard & Mouse Set120.004w,1d$20.710.004.001.005.000.7120.714.001.002.8682.86
2103/01/22Computer Tower1500.004w,1d$517.860.004.001.00125.0017.86517.864.001.0071.432071.43
22End Date            
2303/30/22            
24            
25            
26            
27Subtotal$849.29  
28Discount$0.00  
29Net Amount$849.29  
30TOTAL AMOUNT$849.29  
31
32DescriptionQTYUnit RateWeeksItem Subtotal[ Term ]MonthsWeeksDaysWeekly RateDaily RateSubtotalWeeksDaysDaily RateSubtotal
33Computer Monitor1200.006d$171.42Months0.000.006.0050.007.1442.840.006.0028.57171.42
34Speaker Set250.006d$85.68Weeks0.000.006.0012.501.7921.480.006.007.1485.68
35Start DateKeyboard & Mouse Set120.006d$17.160.000.006.005.000.714.260.006.002.8617.16
3604/01/22Computer Tower1500.006d$428.580.000.006.00125.0017.86107.160.006.0071.43428.58
37End Date            
3804/07/22            
39            
40            
41            
42Subtotal$702.84  
43Discount$0.00  
44Net Amount$702.84  
45TOTAL AMOUNT$702.84  
Sheet 2
Cell Formulas
RangeFormula
I18:I26I18=IF(ISBLANK(C18),"",DATEDIF($A$21,$A$23,"M"))
J18:J26J18=IF(ISBLANK(C18),"",INT(($A$23-EDATE($A$21,DATEDIF($A$21,$A$23,"m")))/7))
K18:K26K18=IF(ISBLANK(C18),"",MOD($A$23-EDATE($A$21,DATEDIF($A$21,$A$23,"m")),7))
L33:L41,L18:L26L18=IF(ISBLANK(C18),"",(ROUND(D18/4,2)))
M33:M41,M18:M26M18=IF(ISBLANK(C18),"",(ROUND(L18/7,2)))
N33:N41,N18:N26N18=IF(ISBLANK(C18),"",(D18*I18+L18*J18+M18*K18)*C18)
P18:P26P18=IF(ISBLANK(C18),"",INT((DATEDIF($A$21,$A$23,"d")/7)))
Q18:Q26Q18=IF(ISBLANK(C18),"",MOD($A$23-EDATE($A$21,DATEDIF($A$21,$A$23,"m")),7))
R33:R41,R18:R26R18=IF(ISBLANK(C18),"",(ROUND(D18/7,2)))
S33:S41,S18:S26S18=IF(ISBLANK(C18),"",(D18*P18+R18*Q18)*C18)
E18:E26E18=IF(OR($B18="",AND(E$17<>"Months",E$17<>"Weeks")),"", SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(E$17="Months",DATEDIF($A$21,$A$23,"m")&"m,"&INT(($A$23-EDATE($A$21,DATEDIF($A$21,$A$23,"m")))/7)&"w,"&MOD($A$23-EDATE($A$21,DATEDIF($A$21,$A$23,"m")),7)&"d", INT(($A$23-$A$21)/7)&"w,"&MOD($A$23-$A$21,7)&"d"),"0m,",""),"0w,",""),",0d",""))
F18:F26F18=IF(ISBLANK(C18),"",IF(E$17="Months",(D18*I18+L18*J18+M18*K18)*C18,IF(E$17="Weeks",((D18*P18+R18*Q18)*C18))))
F27F27=SUBTOTAL(109,Table2261013[Item Subtotal])
L42:L45,L27:L30L27=IF(ISBLANK(C22),"",(ROUND(K27/7,2)))
M42:M45,M27:M30M27=IF(ISBLANK(C22),"",(D22*H27+K27*I27+L27*J27)*C22)
F29,F44F29=(F27-(F27*F28))
F30,F45F30=F29
I33:I41I33=IF(ISBLANK(C33),"",DATEDIF($A$36,$A$38,"M"))
J33:J41J33=IF(ISBLANK(C33),"",INT(($A$38-EDATE($A$36,DATEDIF($A$36,$A$38,"m")))/7))
K33:K41K33=IF(ISBLANK(C33),"",MOD($A$38-EDATE($A$36,DATEDIF($A$36,$A$38,"m")),7))
P33:P41P33=IF(ISBLANK(C33),"",INT((DATEDIF($A$36,$A$38,"d")/7)))
Q33:Q41Q33=IF(ISBLANK(C33),"",MOD($A$38-EDATE($A$36,DATEDIF($A$36,$A$38,"m")),7))
E33:E41E33=IF(OR($B33="",AND(E$32<>"Months",E$32<>"Weeks")),"", SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(E$32="Months",DATEDIF($A$36,$A$38,"m")&"m,"&INT(($A$38-EDATE($A$36,DATEDIF($A$36,$A$38,"m")))/7)&"w,"&MOD($A$38-EDATE($A$36,DATEDIF($A$36,$A$38,"m")),7)&"d", INT(($A$38-$A$36)/7)&"w,"&MOD($A$38-$A$36,7)&"d"),"0m,",""),"0w,",""),",0d",""))
F33:F41F33=IF(ISBLANK(C33),"",IF(E$32="Months",(D33*I33+L33*J33+M33*K33)*C33,IF(E$32="Weeks",((D33*P33+R33*Q33)*C33))))
F42F42=SUBTOTAL(109,Table226101316[Item Subtotal])
Cells with Data Validation
CellAllowCriteria
E17List=$H$1:$H$3
E32List=$H$1:$H$3
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top