Formula to repeat a value starting at x year and repeating y years

Robert Davidson

New Member
Joined
Aug 8, 2023
Messages
29
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I am preparing a cashflow model which has a column with years starting at say 2023 going on for several decades. I wish to make a periodic income in the adjacent column that starts in say 2025 then repeats every say 3 years. Could someone help construct a formula for this? The start year, the income, the first income year and the frequency all need to be variables. An example would be. The aim is to produce a periodic income for a NPV calculation arising from felling trees so the frequency could be up to perhaps 120 years.

YearIncome
20230
20240
20251000
20260
20270
20281000
20290
20300
20311000
 
Full explanation in the screenshot:
Excelpic2.png
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I am not clear on the relationship between the last note (effectively "cut cashflow in 2100") and cell B3 (Model duration = 1000).
Does B3 mean the table goes for 1000 rows? Seems very long!!?
If so, does B7 mean that income stops in 2100 but costs continue for the whole 1000 rows?
 
Upvote 0
Robert, you can try the below formula :

=LET(s,SEQUENCE(IF((B2+B3)>B7,B7-B2+1,B3),,B2),HSTACK(s,BYROW(s,LAMBDA(y,IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6,B4)=0),B5,0))),BYROW(s,LAMBDA(y,IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6-B9,B4)=0),-B8,0))),BYROW(s,LAMBDA(y,IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6,B4)=0),ROUND(B5/(1+B11)^(y-B2),2),IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6-B9,B4)=0),ROUND(-B8/(1+B11)^(y-B2),2),0))))))
 
Upvote 0
Robert, you can try the below formula :

=LET(s,SEQUENCE(IF((B2+B3)>B7,B7-B2+1,B3),,B2),HSTACK(s,BYROW(s,LAMBDA(y,IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6,B4)=0),B5,0))),BYROW(s,LAMBDA(y,IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6-B9,B4)=0),-B8,0))),BYROW(s,LAMBDA(y,IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6,B4)=0),ROUND(B5/(1+B11)^(y-B2),2),IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6-B9,B4)=0),ROUND(-B8/(1+B11)^(y-B2),2),0))))))
I am not clear on the relationship between the last note (effectively "cut cashflow in 2100") and cell B3 (Model duration = 1000).
Does B3 mean the table goes for 1000 rows? Seems very long!!?
If so, does B7 mean that income stops in 2100 but costs continue for the whole 1000 rows?
Peter, Sorry I wasn't that clear. Discounting and working out nett present value (the sum of the discounted column) requires long time frames to ensure the values in the discounted column eventually turn to zero. I should really re-label B7 to be last income and last costs. The reason I need to cut cost and income at some point in the future is that a block of trees might be being felled and replanted as normal then the landuse is changed for that block to be, for example, a wind farm (as happens here in the UK). Thus income and costs associated with forestry stop. Hopefully that makes sense.
 
Upvote 0
Robert, you can try the below formula :

=LET(s,SEQUENCE(IF((B2+B3)>B7,B7-B2+1,B3),,B2),HSTACK(s,BYROW(s,LAMBDA(y,IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6,B4)=0),B5,0))),BYROW(s,LAMBDA(y,IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6-B9,B4)=0),-B8,0))),BYROW(s,LAMBDA(y,IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6,B4)=0),ROUND(B5/(1+B11)^(y-B2),2),IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6-B9,B4)=0),ROUND(-B8/(1+B11)^(y-B2),2),0))))))
Thank you for your help Sanjeev. Have you tried setting B9 (restocking delay) to zero? If I do that with your above formula the number in the discounted column appears to only discount income and does not discount cost. If I leave B7 blank then the above formula shows VALUE! If that is blank then I would want the default length to be per Model Duration. Also, I realise that if there is a restocking delay then that should be added to the rotation. For example a 2 year delay plus a 5 year rotation would effectively make the real length of the rotation 2 + 5 = 7.
 
Upvote 0
@Robert Davidson
If you are still needing help with this, could you please address the issues raised in my previous post?
Peter, Sorry I wasn't that clear plus I had replied earlier but the reply seems to have come up in the response to Sanjeev. Discounting and working out nett present value (the sum of the discounted column) requires long time frames to ensure the values in the discounted column eventually turn to zero. I should really re-label B7 to be last income and last costs. The reason I need to cut cost and income at some point in the future is that a block of trees might be being felled and replanted as normal then the landuse is changed for that block to be, for example, a wind farm (as happens here in the UK). Thus income and costs associated with forestry stop. Hopefully that makes sense.
 
Upvote 0
Robert, you can try the below. Hope it takes care of all your points.

=LET(s,SEQUENCE(IF((B2+B3)>=MIN(B7,B2+B3),IF(B7>B2,B7-B2+1,B3),B3),,B2),HSTACK(s,BYROW(s,LAMBDA(y,IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6,B4)=0),B5,0))),BYROW(s,LAMBDA(y,IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6-B9,B4)=0),-B8,0))),BYROW(s,LAMBDA(y,IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6,B4)=0),ROUND(IF(AND(B9=0,B8>0),(B5-B8),B5)/(1+B11)^(y-B2),2),IF(AND(y>=B6,IF(ISBLANK(B7),B2+B3,y<=B7),MOD(y-B6-B9,B4)=0),ROUND(-B8/(1+B11)^(y-B2),2),0))))))
 
Upvote 0
I had replied earlier but the reply seems to have come up in the response to Sanjeev.
Ah, I see. I had not expanded that quote so missed the reply. You have embedded quotes within quotes and put replies in original quotes so you need to try to sort that out going forward. ;)

Does this do what you want?

Robert Davidson.xlsm
ABCDEFG
1YearIncomeCostDiscounted
2Start202420240.000.000.00
3Model Duration100020250.000.000.00
4Rotation3202624,000.000.0022,622.30
5Income2400020270.00-3,500.00-3,203.00
6First felling202620280.000.000.00
7Last income & costs2100202924,000.000.0020,702.61
8Restocking cost350020300.00-3,500.00-2,931.19
9Restocking delay120310.000.000.00
10203224,000.000.0018,945.82
11Discount Rate3%20330.00-3,500.00-2,682.46
1220340.000.000.00
13203524,000.000.0017,338.11
1420360.00-3,500.00-2,454.83
1520370.000.000.00
16203824,000.000.0015,866.83
1720390.00-3,500.00-2,246.52
1820400.000.000.00
19204124,000.000.0014,520.39
2020420.00-3,500.00-2,055.88
2120430.000.000.00
22204424,000.000.0013,288.22
2320450.00-3,500.00-1,881.42
2420460.000.000.00
25204724,000.000.0012,160.60
2620480.00-3,500.00-1,721.77
2720490.000.000.00
28205024,000.000.0011,128.67
2920510.00-3,500.00-1,575.66
3020520.000.000.00
31205324,000.000.0010,184.31
3220540.00-3,500.00-1,441.95
3320550.000.000.00
34205624,000.000.009,320.09
3520570.00-3,500.00-1,319.59
3620580.000.000.00
37205924,000.000.008,529.20
3820600.00-3,500.00-1,207.61
3920610.000.000.00
40206224,000.000.007,805.43
4120630.00-3,500.00-1,105.14
4220640.000.000.00
43206524,000.000.007,143.07
4420660.00-3,500.00-1,011.36
4520670.000.000.00
46206824,000.000.006,536.92
4720690.00-3,500.00-925.54
4820700.000.000.00
49207124,000.000.005,982.21
5020720.00-3,500.00-847.00
5120730.000.000.00
52207424,000.000.005,474.57
5320750.00-3,500.00-775.12
5420760.000.000.00
55207724,000.000.005,010.01
5620780.00-3,500.00-709.35
5720790.000.000.00
58208024,000.000.004,584.87
5920810.00-3,500.00-649.15
6020820.000.000.00
61208324,000.000.004,195.80
6220840.00-3,500.00-594.07
6320850.000.000.00
64208624,000.000.003,839.75
6520870.00-3,500.00-543.65
6620880.000.000.00
67208924,000.000.003,513.92
6820900.00-3,500.00-497.52
6920910.000.000.00
70209224,000.000.003,215.73
7120930.00-3,500.00-455.30
7220940.000.000.00
73209524,000.000.002,942.85
7420960.00-3,500.00-416.67
7520970.000.000.00
76209824,000.000.002,693.13
7720990.00-3,500.00-381.31
7821000.000.000.00
7921010.000.000.00
8021020.000.000.00
8121030.000.000.00
Cashflow (3)
Cell Formulas
RangeFormula
D2:G1001D2=LET(yr,SEQUENCE(B3,,B2),inc,BYROW(yr,LAMBDA(y,IF(AND(y>=B6,y<=B7,MOD(y-B6,B4)=0),B5,0))),dinc,BYROW(yr,LAMBDA(y,IF(AND(y>=B6,y<=B7,MOD(y-B6,B4)=0),ROUND(B5/(1+B11)^(y-B2),2),0))),cost,-BYROW(yr,LAMBDA(y,IF(AND(y>=B6,y<=B7,MOD(y-B6,B4)=B9),B8,0))),dcost,-BYROW(yr,LAMBDA(y,IF(AND(y>=B6,y<=B7,MOD(y-B6,B4)=B9),ROUND(B8/(1+B11)^(y-B2),2),0))),HSTACK(yr,inc,cost,dinc+dcost))
Dynamic array formulas.


If so, I don't see any point in cell B3 (Model Duration) since the duration is already limited by 'Last Income & Costs' in B7. So you could use this instead.

Robert Davidson.xlsm
ABCDEFG
1YearIncomeCostDiscounted
2Start202420240.000.000.00
3Rotation320250.000.000.00
4Income24000202624,000.000.0022,622.30
5First felling202620270.00-3,500.00-3,203.00
6Last income & costs210020280.000.000.00
7Restocking cost3500202924,000.000.0020,702.61
8Restocking delay120300.00-3,500.00-2,931.19
920310.000.000.00
10Discount Rate3%203224,000.000.0018,945.82
1120330.00-3,500.00-2,682.46
1220340.000.000.00
13203524,000.000.0017,338.11
1420360.00-3,500.00-2,454.83
1520370.000.000.00
16203824,000.000.0015,866.83
1720390.00-3,500.00-2,246.52
1820400.000.000.00
19204124,000.000.0014,520.39
2020420.00-3,500.00-2,055.88
2120430.000.000.00
22204424,000.000.0013,288.22
2320450.00-3,500.00-1,881.42
2420460.000.000.00
25204724,000.000.0012,160.60
2620480.00-3,500.00-1,721.77
2720490.000.000.00
28205024,000.000.0011,128.67
2920510.00-3,500.00-1,575.66
3020520.000.000.00
31205324,000.000.0010,184.31
3220540.00-3,500.00-1,441.95
3320550.000.000.00
34205624,000.000.009,320.09
3520570.00-3,500.00-1,319.59
3620580.000.000.00
37205924,000.000.008,529.20
3820600.00-3,500.00-1,207.61
3920610.000.000.00
40206224,000.000.007,805.43
4120630.00-3,500.00-1,105.14
4220640.000.000.00
43206524,000.000.007,143.07
4420660.00-3,500.00-1,011.36
4520670.000.000.00
46206824,000.000.006,536.92
4720690.00-3,500.00-925.54
4820700.000.000.00
49207124,000.000.005,982.21
5020720.00-3,500.00-847.00
5120730.000.000.00
52207424,000.000.005,474.57
5320750.00-3,500.00-775.12
5420760.000.000.00
55207724,000.000.005,010.01
5620780.00-3,500.00-709.35
5720790.000.000.00
58208024,000.000.004,584.87
5920810.00-3,500.00-649.15
6020820.000.000.00
61208324,000.000.004,195.80
6220840.00-3,500.00-594.07
6320850.000.000.00
64208624,000.000.003,839.75
6520870.00-3,500.00-543.65
6620880.000.000.00
67208924,000.000.003,513.92
6820900.00-3,500.00-497.52
6920910.000.000.00
70209224,000.000.003,215.73
7120930.00-3,500.00-455.30
7220940.000.000.00
73209524,000.000.002,942.85
7420960.00-3,500.00-416.67
7520970.000.000.00
76209824,000.000.002,693.13
7720990.00-3,500.00-381.31
7821000.000.000.00
79
Cashflow (4)
Cell Formulas
RangeFormula
D2:G78D2=LET(yr,SEQUENCE(B6-B2+1,,B2),inc,BYROW(yr,LAMBDA(y,IF(AND(y>=B5,MOD(y-B5,B3)=0),B4,0))),dinc,BYROW(yr,LAMBDA(y,IF(AND(y>=B5,MOD(y-B5,B3)=0),ROUND(B4/(1+B10)^(y-B2),2),0))),cost,-BYROW(yr,LAMBDA(y,IF(AND(y>=B5,MOD(y-B5,B3)=B8),B7,0))),dcost,-BYROW(yr,LAMBDA(y,IF(AND(y>=B5,MOD(y-B5,B3)=B8),ROUND(B7/(1+B10)^(y-B2),2),0))),HSTACK(yr,inc,cost,dinc+dcost))
Dynamic array formulas.
 
Upvote 1
Solution
Dear Peter,
Thank you very much for all your help. Both are helpful but I will stick with the option to continue on the model period while truncating the cashflow early as I will use a series of these formulae for calculating the values of each part of a forest as each one can then be treated differently but the cash flow can be seen to terminate at a common year.
Robert.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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