Practice / window functions

Running Revenue

hard

Corner Store Co. logs each day's takings and wants a running total per store — the revenue so far, growing row by row.

daily

A store can post two rows on the same day (two takings entries). The running total should step through them one row at a time, so within that day the total climbs with each row.

Your task: for each row return store, day, amount, and a running_total — the cumulative sum of amount within that store, ordered by day, adding one row at a time up to and including the current row.

Assign your answer DataFrame to result. Row order doesn't matter.

dailyinput DataFrame

Schema
columntype
storestring
daystring
amountdouble
Sample rows
storedayamount
Downtown2026-06-0110
Downtown2026-06-0110
Downtown2026-06-028
Pier2026-06-014
Pier2026-06-026
Expected output shape
storedayamountrunning_total· 5 rows
Hint

Window.partitionBy("store").orderBy("day").rowsBetween(Window.unboundedPreceding, Window.currentRow), then F.sum("amount").over(w). The explicit rowsBetween matters — it steps one row at a time even when a store has two rows on the same day.

Lesson refresher

This problem builds on Window Functions (~9 min). Pop it open in a new tab if you want a quick recap.

Loading editor…
Hit Run to execute your code and see the output here.