Shape · Time series

Diff / Pct Change

Compares each row with the one N periods earlier and writes the difference or percent change. For example, month-over-month growth per store.

Also known as: Growth rate, year over year

How it works

Group by restarts the comparison per group and Order by is required. Pick the Column to measure, a Method (Diff or Pct Change) and the number of Periods to look back, 1 by default and never below 1. Diff writes current - previous; Pct Change writes (current - previous) / previous as a fraction, so 0.12 means 12 percent, and gives NULL when the previous value is 0. The first rows of each group, which have nothing to compare to, are NULL. The result is appended as column_diff or column_pct_change unless you set an Output column.

Inputs and outputs

Inputs

  • data — Table

Outputs

  • data — Table

Settings

The Attributes panel of Diff / Pct Change, as in the app: the controls work, but nothing runs — there is no data behind it.

The same settings, as the Assistant writes them
{
  column: string
  periods: number
  method: "diff"|"pct_change"
  outputColumn?: string
  orderBy: [{ column, direction }]
  groupBy?: string[]
}

Example

Month-over-month growth per store: column sales, method Pct Change, periods 1, order by month, group by store. For year-over-year on monthly rows, set periods to 12.

storemonthsalessales_pct_change
A2024-01120NULL
A2024-021350.125
A2024-03128-0.0519