Shape · Time series

Rolling Window

Adds moving statistics over the last N rows: sum, average, standard deviation, min, max, count or median. For example, a 7-day moving average.

Also known as: Moving average

How it works

Group by restarts the frame per group, and Order by, which is required, sets the row order. Window is the frame size in rows (3 by default): each row is combined with the rows before it up to that count. Min periods defaults to the window; a row whose frame holds fewer non-null values than that gets NULL, so with the default the first window minus one rows of each group are NULL. Each operation picks a statistic (Sum, Count, Average, Min, Max, Median or Std dev) and a column; the result is appended as, for example, Rolling 7-Mean of sales unless you name it.

Inputs and outputs

Inputs

  • data — Table

Outputs

  • data — Table

Settings

The Attributes panel of Rolling Window, as in the app: the controls work, but nothing runs — there is no data behind it.

The same settings, as the Assistant writes them
{
  operations: [{ statistic: "sum"|"mean"|"std"|"min"|"max"|"count"|"median", column: string, outputColumn?: string }]
  window: number
  minPeriods?: number
  orderBy: [{ column, direction }]
  groupBy?: string[]
}

Example

A 7-day moving average of daily sales per store: window 7, order by day, group by store, one operation with statistic Average on sales and output sales_7d. Set Min periods to 1 if you want a value from the first day, averaged over the rows available so far.