Section: Moving windows

Centered moving average

sql
sql
SELECT day,
       value,
       AVG(value) OVER (
         ORDER BY day
         ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
       ) AS centered_avg_3
FROM metrics;
Explanation

A centered frame is useful for smoothing but depends on future rows being present.

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
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.