Can anyone help me to generate the below attached output in SQL SERVER
Excel Formula to generate NAV
=(B2+(B2*A3))
Can anyone help me to generate the below attached output in SQL SERVER
Excel Formula to generate NAV
=(B2+(B2*A3))
I think that you want the function LAG() which gets the value from the previous row.
Please check this example on dbFiddle. Link at the bottom.
select ret "return", coalesce(lag(nav) over (order by inserted_date),100) + (ret * coalesce(lag(nav) over (order by inserted_date),100) ) "nav", inserted_date from t GO
return | nav | inserted_date -------: | -------------: | :------------ 0.00000 | 100.0000000000 | 2022-01-10 0.01600 | 101.6000000000 | 2022-01-11 -0.00150 | 101.4476000000 | 2022-01-12 0.01030 | 102.4925102800 | 2022-01-13 0.00030 | 102.5232577530 | 2022-01-14 0.00090 | 102.6155309340 | 2022-01-15 0.00000 | 102.6155300000 | 2022-01-16 0.00000 | 102.6155300000 | 2022-01-17 0.09700 | 112.5692364100 | 2022-01-18 -0.01660 | 110.7005906160 | 2022-01-19 -0.00230 | 110.4459786430 | 2022-01-20 -0.00260 | 110.1588104780 | 2022-01-21 -0.02820 | 107.0523412760 | 2022-01-22 0.00000 | 107.0523400000 | 2022-01-23 0.00000 | 107.0523400000 | 2022-01-24 -0.04560 | 102.1707532960 | 2022-01-25 0.01320 | 103.5194039000 | 2022-01-26 0.00000 | 103.5194000000 | 2022-01-27 -0.01020 | 102.4635021200 | 2022-01-28 0.00750 | 103.2319863250 | 2022-01-29 0.00000 | 103.2319800000 | 2022-01-30 0.00000 | 103.2319800000 | 2022-01-31 0.01730 | 105.0178932540 | 2022-02-01 0.00360 | 105.3959644400 | 2022-02-02 0.01180 | 106.6396323280 | 2022-02-03 -0.00710 | 105.8824886270 | 2022-02-04
db<>fiddle here