How can I sum(ctc) in one line with a single statement that IDs from 1/1/2023 still exist on 6/1/2023? so I tried the below statement but returned 0!
SUM( CASE WHEN ID = LAG(ID) OVER (PARTITION BY GP ORDER BY Date- 5 MONTH)
THEN SUM(FLOAT(value)) ELSE 0 END) AS count
I also tried this :
case when date = Date- 5 MONTH then
coalesce(
lag(value) over(
partition by id, case when date = eDate- 5 MONTH then 1 else 0 end
order by date
),
0
)
end AS PrevValue
dbfiddle Link to sample data!

Use a correlated subquery like here:
fiddle