I have table with a amount column which has both negative and positive values.I want to calculate the sum of values and set negative cumulative sum to zero.
date amount actu_cusum exp_cusum
22-06-2018 60.626 60.626 60.626
29-06-2018 -78.309 -17.683 0
02-07-2018 -0.824 -18.507 0
09-07-2018 -0.822 -19.329 0
10-07-2018 14.79 -4.539 14.79
29-07-2018 20 15.461 34.79
30-07-2018 -30 -24.539 4.79
31-07-2018 15 -9.539 19.79
update a set a.calamount= z.cusum
from #temp a,
( select CustomerCode, date ,amount,
SUM(totaumamount) over ( partition by CustomerCode order by date )
as cusum from #temp
) z
where a.customercode = z.customercode and a.date = z.date