Fiddle Yet another way is to partition the cumulative sum, since the case expression only accounts for init <> 1, we will get the running sum for the rest. We then need to add the offset:
with classify (ts, value, init) as
(
select ts, value
, first_value(date(ts)) over (order by ts) = date(ts) as init
from MyTable
)
select ts, value
, case when init = 1
then value
-- cumulative sum for init = 0
else sum(value) over (partition by init order by ts)
-- add offset
+ (select max(value) from classify where init = 1)
end as valueA
from classify
order by ts
;