I am calculating the value according to the previous row, but when I move to the next row, I cannot perform the calculation according to the calculated data, so my value is NULL. How can I continue the calculation based on the value in the previous calculated row? I request your help in this matter.
My table and query are as follows. The name of the column I want to calculate is the [A??rl?kl? Maliyet] column.
SELECT [ID]
,[Belge Tarihi]
,[Belge No]
,[Belge Tipi]
,[PRODUCT_COST_ID]
,[Birim Maliyet]
,[A??rl?kl? Maliyet]
,CASE WHEN [Belge Tipi] LIKE '%Devir%' THEN [Birim Maliyet]
WHEN [Birim Maliyet] IS NULL THEN LAG([Birim Maliyet]) over (partition by STOCK_ID order by STOCK_ID,[Belge Tarihi])
WHEN [Birim Maliyet] IS NOT NULL THEN (((LAG(Kümülatif)
over (partition by STOCK_ID order by STOCK_ID,[Belge Tarihi]))*
(LAG([Birim Maliyet]) over (partition by STOCK_ID order by STOCK_ID,[Belge Tarihi]))) +
([Giren Miktar]*[Birim Maliyet]))/[Kümülatif] END 'Hareketli_Maliyet'
,[SIRA]
,[Giren Miktar]
,[Ç?kan Miktar]
,[STOCK_ID]
,[FIS_ID]
,[Kümülatif]
FROM
[Cost_Simulation].[dbo].[S?ral?_Maliyetler]
WHERE
STOCK_ID = 1568'
enter image description here