# Formula help (Algorithm help?)

##### New Member
This may be considered an algorithm question rather than Excel, but my question is specific to an implementation in Excel.

I need to reduce a daily rate based on calendar days. From days 1 to 20, the daily rate is 100% of a given rate, at day 21 the rate is reduced by 2%, day 28 an additional 2% and so on every 7 days until day 100. I want to avoid using VBA and I can already accomplish this by using multiple cells to calculate the different values and sum them. But I'm hoping there's a more elegant formula, regardless of how complex, that I can put in a single cell to solve the problem such that A1 contains the full daily rate, A2 contains the total number of days, and A3 gives me the total dollar amount based on the reduction formula. I suspect there's a way to use MOD for this but I haven't been able to figure it out.
 ​

### Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

#### Joe4

Welcome to the Board!

When you say "calendar days", are you talking about the difference between two dates, or the day of the month, or something else?

In cases like this, it is often most helpful if we can see a sample of the data you are working along with your expected results.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.

##### New Member
Joe, thank you for the response.

>>When you say "calendar days", are you talking about the difference between two dates, or the day of the month, or something else?

I'm just referring to sequential days irrespective of their actual date or what day of the week they fall on. On the first day (whenever that is) the payment rate is \$100, but on the 21st day (again, whenever that is) the rate is reduced by 2%. Every 7 days after the 20th day, the rate is reduced an additional 2%.

>> it is often most helpful if we can see a sample of the data you are working along with your expected results.

The 'Sample Data' range below shows the basic concept - a running total based on the rate reduction of 2% every 7 days after the 20th day. I would like to fit all of that into a single row with just 3 columns - the basic rate, the total number of days, and the final sum taking into account the reduction.

For example, for 56 days the desired output would be:

Mr. Excel Desired Output.xlsx
ABC
1RateDaysTotal
2\$ 100.0056\$ 5,378.00
Sheet1

This could be done in VBA or with a lookup table or probably other ways I haven't thought of, but I was hoping to do it with just a single formula in Column C.

Mr Excel Sample Data.xlsx
ABCDE
2\$ 100.001100%\$ 100.00\$ 100.00
3\$ 100.002100%\$ 100.00\$ 200.00
4\$ 100.003100%\$ 100.00\$ 300.00
5\$ 100.004100%\$ 100.00\$ 400.00
6\$ 100.005100%\$ 100.00\$ 500.00
7\$ 100.006100%\$ 100.00\$ 600.00
8\$ 100.007100%\$ 100.00\$ 700.00
9\$ 100.008100%\$ 100.00\$ 800.00
10\$ 100.009100%\$ 100.00\$ 900.00
11\$ 100.0010100%\$ 100.00\$ 1,000.00
12\$ 100.0011100%\$ 100.00\$ 1,100.00
13\$ 100.0012100%\$ 100.00\$ 1,200.00
14\$ 100.0013100%\$ 100.00\$ 1,300.00
15\$ 100.0014100%\$ 100.00\$ 1,400.00
16\$ 100.0015100%\$ 100.00\$ 1,500.00
17\$ 100.0016100%\$ 100.00\$ 1,600.00
18\$ 100.0017100%\$ 100.00\$ 1,700.00
19\$ 100.0018100%\$ 100.00\$ 1,800.00
20\$ 100.0019100%\$ 100.00\$ 1,900.00
21\$ 100.0020100%\$ 100.00\$ 2,000.00
22\$ 100.002198%\$ 98.00\$ 2,098.00
23\$ 100.002298%\$ 98.00\$ 2,196.00
24\$ 100.002398%\$ 98.00\$ 2,294.00
25\$ 100.002498%\$ 98.00\$ 2,392.00
26\$ 100.002598%\$ 98.00\$ 2,490.00
27\$ 100.002698%\$ 98.00\$ 2,588.00
28\$ 100.002798%\$ 98.00\$ 2,686.00
29\$ 100.002896%\$ 96.00\$ 2,782.00
30\$ 100.002996%\$ 96.00\$ 2,878.00
31\$ 100.003096%\$ 96.00\$ 2,974.00
32\$ 100.003196%\$ 96.00\$ 3,070.00
33\$ 100.003296%\$ 96.00\$ 3,166.00
34\$ 100.003396%\$ 96.00\$ 3,262.00
35\$ 100.003496%\$ 96.00\$ 3,358.00
36\$ 100.003594%\$ 94.00\$ 3,452.00
37\$ 100.003694%\$ 94.00\$ 3,546.00
38\$ 100.003794%\$ 94.00\$ 3,640.00
39\$ 100.003894%\$ 94.00\$ 3,734.00
40\$ 100.003994%\$ 94.00\$ 3,828.00
41\$ 100.004094%\$ 94.00\$ 3,922.00
42\$ 100.004194%\$ 94.00\$ 4,016.00
43\$ 100.004292%\$ 92.00\$ 4,108.00
44\$ 100.004392%\$ 92.00\$ 4,200.00
45\$ 100.004492%\$ 92.00\$ 4,292.00
46\$ 100.004592%\$ 92.00\$ 4,384.00
47\$ 100.004692%\$ 92.00\$ 4,476.00
48\$ 100.004792%\$ 92.00\$ 4,568.00
49\$ 100.004892%\$ 92.00\$ 4,660.00
50\$ 100.004990%\$ 90.00\$ 4,750.00
51\$ 100.005090%\$ 90.00\$ 4,840.00
52\$ 100.005190%\$ 90.00\$ 4,930.00
53\$ 100.005290%\$ 90.00\$ 5,020.00
54\$ 100.005390%\$ 90.00\$ 5,110.00
55\$ 100.005490%\$ 90.00\$ 5,200.00
56\$ 100.005590%\$ 90.00\$ 5,290.00
57\$ 100.005688%\$ 88.00\$ 5,378.00
58\$ 100.005788%\$ 88.00\$ 5,466.00
59\$ 100.005888%\$ 88.00\$ 5,554.00
60\$ 100.005988%\$ 88.00\$ 5,642.00
61\$ 100.006088%\$ 88.00\$ 5,730.00
62\$ 100.006188%\$ 88.00\$ 5,818.00
63\$ 100.006288%\$ 88.00\$ 5,906.00
64\$ 100.006386%\$ 86.00\$ 5,992.00
65\$ 100.006486%\$ 86.00\$ 6,078.00
66\$ 100.006586%\$ 86.00\$ 6,164.00
67\$ 100.006686%\$ 86.00\$ 6,250.00
68\$ 100.006786%\$ 86.00\$ 6,336.00
69\$ 100.006886%\$ 86.00\$ 6,422.00
70\$ 100.006986%\$ 86.00\$ 6,508.00
71\$ 100.007084%\$ 84.00\$ 6,592.00
72\$ 100.007184%\$ 84.00\$ 6,676.00
73\$ 100.007284%\$ 84.00\$ 6,760.00
74\$ 100.007384%\$ 84.00\$ 6,844.00
75\$ 100.007484%\$ 84.00\$ 6,928.00
76\$ 100.007584%\$ 84.00\$ 7,012.00
77\$ 100.007684%\$ 84.00\$ 7,096.00
78\$ 100.007782%\$ 82.00\$ 7,178.00
79\$ 100.007882%\$ 82.00\$ 7,260.00
80\$ 100.007982%\$ 82.00\$ 7,342.00
81\$ 100.008082%\$ 82.00\$ 7,424.00
82\$ 100.008182%\$ 82.00\$ 7,506.00
83\$ 100.008282%\$ 82.00\$ 7,588.00
84\$ 100.008382%\$ 82.00\$ 7,670.00
85\$ 100.008480%\$ 80.00\$ 7,750.00
86\$ 100.008580%\$ 80.00\$ 7,830.00
87\$ 100.008680%\$ 80.00\$ 7,910.00
88\$ 100.008780%\$ 80.00\$ 7,990.00
89\$ 100.008880%\$ 80.00\$ 8,070.00
90\$ 100.008980%\$ 80.00\$ 8,150.00
91\$ 100.009080%\$ 80.00\$ 8,230.00
92\$ 100.009178%\$ 78.00\$ 8,308.00
93\$ 100.009278%\$ 78.00\$ 8,386.00
94\$ 100.009378%\$ 78.00\$ 8,464.00
95\$ 100.009478%\$ 78.00\$ 8,542.00
96\$ 100.009578%\$ 78.00\$ 8,620.00
97\$ 100.009678%\$ 78.00\$ 8,698.00
98\$ 100.009778%\$ 78.00\$ 8,776.00
99\$ 100.009876%\$ 76.00\$ 8,852.00
100\$ 100.009976%\$ 76.00\$ 8,928.00
101\$ 100.0010076%\$ 76.00\$ 9,004.00
Sheet1
Cell Formulas
RangeFormula
D2:D101D2=A2*C2
E2E2=D2
E3:E101E3=D3+E2

#### Joe4

Put this formula in cell C2 and copy down for all rows:
Excel Formula:
``=1-IF(B2>20,(INT((B2-21)/7)+1)*0.02,0)``

#### JamesCanale

##### Board Regular

This is incomprehensible - B2 is the number of days, A2 is the \$100:
Excel Formula:
``=SUMPRODUCT((1-INT((((ROW(INDIRECT(1&":"&B2))-14)+ABS((ROW(INDIRECT(1&":"&B2))-14)))/2)/7)*0.02)*A2)``

##### New Member
I appreciate the responses. James' solution did exactly what I was looking for.

#### JamesCanale

##### Board Regular
I appreciate the responses. James' solution did exactly what I was looking for.
Thanks, The Row(Indirect...) part makes an array within the formula that the sumproduct can work on. Perhaps there is a more elegant way of turning negative numbers into zero for the first two weeks - but the usual max(X,0) doesn't work because the max turns the array into a scalar. So I averaged a number and it's absolute value.

Replies
1
Views
32
Replies
3
Views
95
Replies
0
Views
131
Replies
25
Views
177
Replies
1
Views
54

1,127,252
Messages
5,623,624
Members
415,981
Latest member
Baltwin

### 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.

### Which adblocker are you using?

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

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