Below is my SQL code which I am using to generate the MTD numbers , however I am facing an issue with the results as they are not correct , the issue occurring as some of the partner data is available in the first day but not in the next day data set.
how I can include first day ( Missing ) data to be part of the next in order to get the correct MTD number .
SELECT CalendarID,
PartnerID,
DAY_QTY,
SUM (DAY_QTY) OVER (PARTITION BY CalendarID,PartnerID ORDER BY CalendarID) AS MTD_QTY
FROM TEST
ORDER BY CalendarID
My Data Set :
> CalendarID \ PartnerID \ DAY_QTY \ MTD_QTY
20220101 222180 245 20220101 362798 12 20220101 363248 10 20220101 381773 5 20220101 397523 28 20220102 220202 1 20220102 240857 4 20220102 252074 50 20220102 263986 7 20220102 397523 163 20220102 397680 6