LAG & LEAD: Previous and Next Order, Gaps and Changes
This lesson is part of the course
In this lesson
You fetch each customer's previous order date (LAG), the days since that order, the change against the previous amount and the next order date (LEAD) – with formulas that work no matter how the log is sorted.
Buy the course once for $9.99 to unlock every lesson and lab, the final exam and the certificate – lifetime access, no subscription.
Lessons in this course
- PARTITION BY vs GROUP BY: Group Totals Next to Every Row Locked
- Running Totals: Cumulative Sums per Customer, Ties & the Running Share Locked
- ROW_NUMBER, RANK & DENSE_RANK per Group: Ties and Top-n Locked
- LAG & LEAD: Previous and Next Order, Gaps and Changes Locked
- Moving Averages & Rolling Windows: Date Ranges vs Row Counts Locked
- NTILE & PERCENT_RANK: Quartiles, Percentiles and Halves per Group Locked
- FIRST_VALUE & LAST_VALUE: First Orders, Cohort Labels and the Latest Row Locked
- Capstone: Sessionisation – Gaps, New-Session Flags and Session Numbers Locked