Cellwise · SQL track
Comparing with the previous row
Changes from one row to the next, and year-on-year growth.
LAG returns a value from the previous row, in the order you choose. LEAD returns one from the next row. The first row has nothing before it, so LAG gives NULL there.
Subtracting the previous value gives the change, which is how year-on-year reports are built.
What you’ll do
- Show the previous amount
- Work out the change
- Year-on-year change