rangeBetween
Window frames by value instead of row count: the last 7 calendar days, not the last 7 rows.
Step 1 · PySpark functions · Gold · Gold window patterns, lesson 1 of 3
On this page
Read first: row_number / rank · lag / lead (skip if you know them)
In plain words first
Counting "the last 7 pages" of a diary is different from counting "the last 7 days". If you skipped writing on Tuesday, the last 7 pages reach back further than a week.
rowsBetween counts pages (rows); rangeBetween counts days (values of the ordering column). For time-based questions you almost always want the second.
Unlock the full lesson
You have read the free part. The rest of this advanced lesson:
- Frames: which rows the aggregate sees
- Step by step: a 7-day total
- Run the example
- The default frame trap
- Under the hood
- Common mistakes
- Key takeaways
- Interview prep with 3 follow-up questions
- Check yourself: 3 questions
Unlock it with the Complete pass (every advanced problem and lesson) or on its own.
Practise this
Problems that use rangeBetween, graded on hidden tests
- 7-Day Moving AverageWindow Functions Medium
- Fit Conversations into a Context WindowData Prep for AI Hard
- Forward-Fill Missing ReadingsWindow Functions AdvancedHard
Keep going
Up next · Gold window patterns · lesson 2 of 3 · 4 min readlast(ignorenulls)
Forward-fill missing values with last over a window, and the frame that makes it work.
Related lessons
Previous: Testing PySpark code
Primary sources: WindowSpec.rangeBetween · Window functions (SQL)