Section: Moving windows

Running total per category

sql
sql
SELECT month,
       region,
       sales,
       SUM(sales) OVER (
         PARTITION BY region
         ORDER BY month
         ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
       ) AS regional_running_total
FROM monthly_sales;
Explanation

Combining `PARTITION BY` and `ORDER BY` is the backbone of grouped time-series analysis.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Moving windows
3-row moving average
Average current row and previous two rows.
OpenIn sheetsqlsame section
7-row moving sum
Rolling weekly sum on daily rows.
OpenIn sheetsqlsame section
Centered moving average
Use prior and following rows together.
OpenIn sheetsqlsame section
Running total
Cumulative sum ordered by date.
Running count
Count rows seen so far.
Cumulative maximum
Track the best-so-far value.