The depreciation rate is the amount of decrease in the book value of an accounting unit over a year. You want to calculate the amount of depreciation for each day since the purchase of the property.
Daily value is DepreciationRate/(Days in year). We should consider also number of days in year (365 or 366).
So
cross apply( values
( datediff(day
,DateFromParts (year(dateadd(day,(DepreciationDay+0),r.PurchaseDate)),01,01)
,DateFromParts(year(dateadd(day,(DepreciationDay+0),r.PurchaseDate)),12,31))+1
))n(dy) -- days in year
Recursive query adds day by day until limit date and increments Depreciation Rate by day value up to limit 1.0
case when (DepreciationDay+1.0)*DepreciationRate/n.dy<1.0 then
cast((DepreciationDay+1.0)*DepreciationRate/n.dy as decimal(18,9))
else cast(1.0 as decimal(18,9))
end as DepreciationPct ,
See example for SQL Server.
-- INSERT INTO #TetstData VALUES(1, '2019/01/01', 0.123456789);
INSERT INTO #TetstData VALUES(1, '2019/01/01', 0.363456789);
INSERT INTO #TetstData VALUES(2, '2021/01/01', 0.987654321);
WITH cte_daily AS
(
SELECT t.Id, t.PurchaseDate, t.PurchaseDate as DepreciationDate,
cast(1.0*t.DepreciationRate/dy as decimal(18,9)) as DepreciationPct,
t.DepreciationRate,dy, 1 as DepreciationDay,
1 as lvl
FROM #TetstData t
cross apply( values (datediff(day,DateFromParts (year(t.PurchaseDate),01,01)
,DateFromParts(year(t.PurchaseDate),12,31))+1
))n(dy)
union all
SELECT r.Id, r.PurchaseDate, dateadd(day,(DepreciationDay+0),r.PurchaseDate) as DepreciationDate,
case when (DepreciationDay+1.0)*DepreciationRate/n.dy<1.0 then
cast((DepreciationDay+1.0)*DepreciationRate/n.dy as decimal(18,9))
else cast(1.0 as decimal(18,9))
end as DepreciationPct ,
r.DepreciationRate,n.dy, (DepreciationDay+1) as DepreciationDay,
lvl+1 as lvl
FROM cte_daily r
cross apply( values
(datediff(day
,DateFromParts (year(dateadd(day,(DepreciationDay+0),r.PurchaseDate)),01,01)
,DateFromParts(year(dateadd(day,(DepreciationDay+0),r.PurchaseDate)),12,31))+1
))n(dy)
where dateadd(day,(DepreciationDay+0),r.PurchaseDate)<'2023-01-01'
and r.DepreciationPct<1
)
SELECT *
FROM cte_daily
order by id,DepreciationDate
option(maxrecursion 1600))
| Id |
PurchaseDate |
DepreciationDate |
DepreciationPct |
DepreciationRate |
dy |
DepreciationDay |
lvl |
| 1 |
2019-01-01 |
2019-01-01 |
0.000995772 |
0.363456789 |
365 |
1 |
1 |
| 1 |
2019-01-01 |
2019-01-02 |
0.001991544 |
0.363456789 |
365 |
2 |
2 |
| 1 |
2019-01-01 |
2019-01-03 |
0.002987316 |
0.363456789 |
365 |
3 |
3 |
| 1 |
2019-01-01 |
2019-01-04 |
0.003983088 |
0.363456789 |
365 |
4 |
4 |
| 1 |
2019-01-01 |
2019-01-05 |
0.004978860 |
0.363456789 |
365 |
5 |
5 |
| 1 |
2019-01-01 |
2019-01-06 |
0.005974632 |
0.363456789 |
365 |
6 |
6 |
| 1 |
2019-01-01 |
2019-01-07 |
0.006970404 |
0.363456789 |
365 |
7 |
7 |
| 1 |
2019-01-01 |
2019-01-08 |
0.007966176 |
0.363456789 |
365 |
8 |
8 |
| 1 |
2019-01-01 |
2019-01-09 |
0.008961948 |
0.363456789 |
365 |
9 |
9 |
| 1 |
2019-01-01 |
2019-01-10 |
0.009957720 |
0.363456789 |
365 |
10 |
10 |
| 1 |
2019-01-01 |
2019-01-11 |
0.010953492 |
0.363456789 |
365 |
11 |
11 |
| 1 |
2019-01-01 |
2019-01-12 |
0.011949264 |
0.363456789 |
365 |
12 |
12 |
| 1 |
2019-01-01 |
2019-01-13 |
0.012945036 |
0.363456789 |
365 |
13 |
13 |
| 1 |
2019-01-01 |
2019-01-14 |
0.013940808 |
0.363456789 |
365 |
14 |
14 |
| 1 |
2019-01-01 |
2019-01-15 |
0.014936580 |
0.363456789 |
365 |
15 |
15 |
| 1 |
2019-01-01 |
2019-01-16 |
0.015932352 |
0.363456789 |
365 |
16 |
16 |
| 1 |
.......... |
............ |
............ |
........... |
... |
. |
. |
| 1 |
2019-01-01 |
2019-12-26 |
0.358477929 |
0.363456789 |
365 |
360 |
360 |
| 1 |
2019-01-01 |
2019-12-27 |
0.359473701 |
0.363456789 |
365 |
361 |
361 |
| 1 |
2019-01-01 |
2019-12-28 |
0.360469473 |
0.363456789 |
365 |
362 |
362 |
| 1 |
2019-01-01 |
2019-12-29 |
0.361465245 |
0.363456789 |
365 |
363 |
363 |
| 1 |
2019-01-01 |
2019-12-30 |
0.362461017 |
0.363456789 |
365 |
364 |
364 |
| 1 |
2019-01-01 |
2019-12-31 |
0.363456789 |
0.363456789 |
365 |
365 |
365 |
| 1 |
2019-01-01 |
2020-01-01 |
0.364452561 |
0.363456789 |
365 |
366 |
366 |
| 1 |
2019-01-01 |
2020-01-02 |
0.365448333 |
0.363456789 |
365 |
367 |
367 |
| 1 |
2019-01-01 |
2020-01-03 |
0.366444105 |
0.363456789 |
365 |
368 |
368 |
| 1 |
2019-01-01 |
2020-01-04 |
0.367439877 |
0.363456789 |
365 |
369 |
369 |
| 1 |
2019-01-01 |
2020-01-05 |
0.368435649 |
0.363456789 |
365 |
370 |
370 |
| 1 |
.......... |
............ |
............ |
........... |
... |
. |
. |
| 1 |
2019-01-01 |
2020-12-25 |
0.721934718 |
0.363456789 |
365 |
725 |
725 |
| 1 |
2019-01-01 |
2020-12-26 |
0.722930490 |
0.363456789 |
365 |
726 |
726 |
| 1 |
2019-01-01 |
2020-12-27 |
0.723926262 |
0.363456789 |
365 |
727 |
727 |
| 1 |
2019-01-01 |
2020-12-28 |
0.724922034 |
0.363456789 |
365 |
728 |
728 |
| 1 |
2019-01-01 |
2020-12-29 |
0.725917806 |
0.363456789 |
365 |
729 |
729 |
| 1 |
2019-01-01 |
2020-12-30 |
0.726913578 |
0.363456789 |
365 |
730 |
730 |
| 1 |
2019-01-01 |
2020-12-31 |
0.727909350 |
0.363456789 |
365 |
731 |
731 |
| 1 |
2019-01-01 |
2021-01-01 |
0.728905122 |
0.363456789 |
365 |
732 |
732 |
| 1 |
2019-01-01 |
2021-01-02 |
0.729900894 |
0.363456789 |
365 |
733 |
733 |
| 1 |
2019-01-01 |
2021-09-24 |
0.993780481 |
0.363456789 |
365 |
998 |
998 |
| 1 |
2019-01-01 |
2021-09-25 |
0.994776253 |
0.363456789 |
365 |
999 |
999 |
| 1 |
2019-01-01 |
2021-09-26 |
0.995772025 |
0.363456789 |
365 |
1000 |
1000 |
| 1 |
2019-01-01 |
2021-09-27 |
0.996767797 |
0.363456789 |
365 |
1001 |
1001 |
| 1 |
2019-01-01 |
2021-09-28 |
0.997763569 |
0.363456789 |
365 |
1002 |
1002 |
| 1 |
2019-01-01 |
2021-09-29 |
0.998759341 |
0.363456789 |
365 |
1003 |
1003 |
| 1 |
2019-01-01 |
2021-09-30 |
0.999755113 |
0.363456789 |
365 |
1004 |
1004 |
| 1 |
2019-01-01 |
2021-10-01 |
1.000000000 |
0.363456789 |
365 |
1005 |
1005 |
| 2 |
2021-01-01 |
2021-01-01 |
0.002705902 |
0.987654321 |
365 |
1 |
1 |
| 2 |
2021-01-01 |
2021-01-02 |
0.005411804 |
0.987654321 |
365 |
2 |
2 |
| 2 |
2021-01-01 |
2021-01-03 |
0.008117707 |
0.987654321 |
365 |
3 |
3 |
| 2 |
2021-01-01 |
2021-01-04 |
0.010823609 |
0.987654321 |
365 |
4 |
4 |
| 2 |
2021-01-01 |
2021-01-05 |
0.013529511 |
0.987654321 |
365 |
5 |
5 |
| 2 |
2021-01-01 |
2021-01-06 |
0.016235413 |
0.987654321 |
365 |
6 |
6 |
| 2 |
2021-01-01 |
2021-01-07 |
0.018941316 |
0.987654321 |
365 |
7 |
7 |
| 2 |
.......... |
............ |
............ |
........... |
... |
. |
. |
| 2 |
2021-01-01 |
2021-12-27 |
0.976830712 |
0.987654321 |
365 |
361 |
361 |
| 2 |
2021-01-01 |
2021-12-28 |
0.979536614 |
0.987654321 |
365 |
362 |
362 |
| 2 |
2021-01-01 |
2021-12-29 |
0.982242517 |
0.987654321 |
365 |
363 |
363 |
| 2 |
2021-01-01 |
2021-12-30 |
0.984948419 |
0.987654321 |
365 |
364 |
364 |
| 2 |
2021-01-01 |
2021-12-31 |
0.987654321 |
0.987654321 |
365 |
365 |
365 |
| 2 |
2021-01-01 |
2022-01-01 |
0.990360223 |
0.987654321 |
365 |
366 |
366 |
| 2 |
2021-01-01 |
2022-01-02 |
0.993066125 |
0.987654321 |
365 |
367 |
367 |
| 2 |
2021-01-01 |
2022-01-03 |
0.995772028 |
0.987654321 |
365 |
368 |
368 |
| 2 |
2021-01-01 |
2022-01-04 |
0.998477930 |
0.987654321 |
365 |
369 |
369 |
| 2 |
2021-01-01 |
2022-01-05 |
1.000000000 |
0.987654321 |
365 |
370 |
370 |
The rules for calculating depreciation may differ slightly from those given by me, but they are basically the same.
fiddle
DepreciationRateget replicated across the new dates?