Lead and lag for time series analysis
As we have already read in the previous chapters, LEAD
and LAG
functions are used to refer to the previous or next row in the dataset for a specific column. Let’s start understanding this with an example.
Case scenario
Imagine you have a table that tracks the number of sales made by a company each month, as follows:
Month |
Sales |
1/1/2021 |
100 |
2/1/2021 |
150 |
3/1/2021 |
200 |
4/1/2021 |
250 |
5/1/2021 |
300 |
6/1/2021 |
350 |
7/1/2021 |
400 |
8/1/2021 |
450 | ...