Section: Moving windows

7-row moving sum

sql
sql
SELECT day,
       revenue,
       SUM(revenue) OVER (
         ORDER BY day
         ROWS BETWEEN 6 PRECEDING AND CURRENT ROW
       ) AS moving_sum_7
FROM daily_revenue;
Explanation

This is a common KPI smoothing pattern for dashboards.

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
Centered moving average
Use prior and following rows together.
OpenIn sheetsqlsame section
Running total per category
Reset the running total by partition.
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.