I'm create a Data Engineer model in Snowflake where I need to calculate the projection at weekly level
Formula to calculate the projection : (left over supply in previous week) + (current week supply) - (current week demand)
TABLE
Supply | Demand | Week_Start_Date |
---|---|---|
1500 | 500 | 15-04-2024 |
0 | 500 | 22-04-2024 |
0 | 500 | 29-04-2024 |
0 | 500 | 06-05-2024 |
500 | 500 | 20-05-2024 |
0 | 500 | 03-06-2024 |
0 | 500 | 10-06-2024 |
0 | 500 | 17-06-2024 |
10000 | 500 | 24-06-2024 |
0 | 500 | 01-07-2024 |
0 | 500 | 08-07-2024 |
OUTPUT
Supply | Demand | Week_Start_Date | Proj |
---|---|---|---|
1500 | 500 | 15-04-2024 | 1000 |
0 | 500 | 22-04-2024 | 500 |
0 | 500 | 29-04-2024 | 0 |
0 | 500 | 06-05-2024 | -500 |
500 | 500 | 20-05-2024 | -500 |
0 | 500 | 03-06-2024 | -1000 |
0 | 500 | 10-06-2024 | -1500 |
0 | 500 | 17-06-2024 | -2000 |
10000 | 500 | 24-06-2024 | 7500 |
0 | 500 | 01-07-2024 | 7000 |
0 | 500 | 08-07-2024 | 6500 |
Created some solution using LAG window function to calculate projection but not getting the desired output