I am using sql in Big Query superset to create a pivot table to calculate the difference of a game between a range of days:
Game Date Sum Prev_sum
First 2022-08-15 178.68
2022-08-16 345.09 166.41
2022-08-18 570.53 991.89 --wrong input ,missing day
2022-08-19 173.69 -396.84
2022-08-20 532.35 358.66
2022-08-21 248.35 -284
Second 2022-08-17 518.59 600.53 --wrong input ,missing day
2022-08-20 182.91 148.3
Third 2022-08-15 527.35
2022-08-17 359.93 426.53
2022-08-20 539.05 564.57
2022-08-21 543.74 4.69
i m using
select Date , SUM(Sum) ,
SUM(Sum) -
lag(SUM(Sum)) over(partition by Game order by min(Date) ASC)
from my_table
ideally i would like to have the difference of sum between each row regardless of the date shown
Game Date Sum Prev_sum
First 2022-08-15 178.68
2022-08-16 345.09 166.41
2022-08-18 570.53 225
2022-08-19 173.69 -396.84
2022-08-20 532.35 358.66
2022-08-21 248.35 -284
Second 2022-08-17 518.59
2022-08-20 182.91 -336