# Resample a time series

Model / timeseries

resample, decompose, difference, smooth, fill time gaps

Page: <https://meridian.online/operations/resample-a-time-series>

## Status

Runs as a SQL step.

arcform carries it as a `sql:` step today.

## The DuckDB step

daily buckets with the gaps filled

It reads the `orders` table the proofs share. Create it first:

```sql
CREATE TABLE orders AS SELECT * FROM (VALUES
  (1,  'Alice Ng',      'north', DATE '2026-01-03', 120.00, 'widget', 'a|b',   '{"channel":"web","items":[1,2]}'),
  (2,  'alice ng',      'north', DATE '2026-01-05',  80.50, 'gadget', 'b',     '{"channel":"shop","items":[3]}'),
  (3,  'Bob  Okafor',   'south', DATE '2026-01-05', 300.00, 'widget', 'a|c',   '{"channel":"web","items":[4,5,6]}'),
  (4,  'Carla Díaz',    'east',  DATE '2026-01-09',  NULL,  'gizmo',  NULL,    '{"channel":"web","items":[]}'),
  (5,  'Bob Okafor',    'south', DATE '2026-01-12',  45.25, 'gadget', 'c',     '{"channel":"phone","items":[7]}'),
  (6,  'Dev Patel',     'west',  DATE '2026-01-12', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (7,  'Carla Diaz',    'east',  DATE '2026-01-20',  99.99, 'gizmo',  'b|c',   '{"channel":"shop","items":[10]}'),
  (8,  'Dev Patel',     'west',  DATE '2026-02-02', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (9,  'Eve Larsen',    NULL,    DATE '2026-02-03',  15.00, 'gadget', NULL,    '{"channel":"web","items":[11]}'),
  (10, 'Alice Ng',      'north', DATE '2026-02-10', 220.00, 'gizmo',  'a|b|c', '{"channel":"phone","items":[12,13]}')
) t(order_id, customer, region, order_date, amount, product, tags, meta);
```

Then run the statement:

```sql
CREATE TEMP TABLE result AS
WITH spine AS (SELECT d::DATE AS day FROM generate_series(DATE '2026-01-03', DATE '2026-01-12', INTERVAL 1 DAY) t(d)),
     daily AS (SELECT order_date AS day, sum(amount) AS total FROM orders GROUP BY 1)
SELECT day, coalesce(total, 0) AS total,
       round(avg(coalesce(total, 0)) OVER (ORDER BY day ROWS BETWEEN 2 PRECEDING AND CURRENT ROW), 2) AS ma3
FROM spine LEFT JOIN daily USING (day) ORDER BY day;
SELECT * FROM result;
SELECT CASE WHEN ((SELECT count(*) = 10 AND max(total) FILTER (WHERE day = DATE '2026-01-05') = 380.5 AND max(total) FILTER (WHERE day = DATE '2026-01-04') = 0 AND max(ma3) FILTER (WHERE day = DATE '2026-01-05') = 166.83 FROM result)) THEN 'as expected' ELSE error('a day with no orders was not filled with 0, or a total is wrong') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## Variants

- Aggregate into regular time windows: Group rows into fixed, hopping or rolling time windows and aggregate each, changing the series' grain.
- [Decompose a series into trend and season](https://meridian.online/operations/resample-a-time-series/decompose-a-series-into-trend-and-season): Split a series into trend, seasonal and remainder parts.
- Difference, accumulate or smooth a series: Replace each value with its change from an earlier one, a running total, or a smoothed value, keeping one row per period.
- Find peaks and summarise a series: Flag or list the peaks of a series, or fit it with a curve and keep the coefficients as features.
- [Fill gaps in a time series](https://meridian.online/operations/resample-a-time-series/fill-gaps-in-a-time-series): Insert rows for missing periods, or interpolate onto evenly spaced time stamps, so the series runs at a regular frequency.
- [Measure autocorrelation or a spectrum](https://meridian.online/operations/resample-a-time-series/measure-autocorrelation-or-a-spectrum): Compute how a series relates to itself across lags, its frequency spectrum, or its load-cycle counts.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 86.2% of 312 rows (exact class, version 2).

- Alteryx Designer: [`AB Trend`](https://help.alteryx.com/current/en/designer/tools/ab-testing/ab-trend-tool.html) (read 2026-09-27)
- Alteryx Designer: [`TS Filler`](https://help.alteryx.com/current/en/designer/tools/time-series/ts-filler-tool.html) (read 2026-09-27)
- Ibis: [`WindowAggregate`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/temporal_windows.py) (read 2026-09-27)
- Polars: [`DataFrame.group_by_dynamic`](https://docs.pola.rs/api/python/stable/reference/dataframe/modify_select.html) (read 2026-09-27)
- Polars: [`DataFrame.upsample`](https://docs.pola.rs/api/python/stable/reference/dataframe/modify_select.html) (read 2026-09-27)
- RapidMiner Studio: [`Autocorrelation / Autocovariance`](https://docs.rapidminer.com/latest/studio/operators/modeling/time_series/transformation/evaluation_function.html) (read 2026-09-27)
- RapidMiner Studio: [`Classic Decomposition`](https://docs.rapidminer.com/latest/studio/operators/modeling/time_series/decomposition/classic_decomposition.html) (read 2026-09-27)
- RapidMiner Studio: [`Differentiate`](https://docs.rapidminer.com/latest/studio/operators/modeling/time_series/transformation/differentiation.html) (read 2026-09-27)
- RapidMiner Studio: [`Equalize Numerical Indices`](https://docs.rapidminer.com/latest/studio/operators/modeling/time_series/transformation/equalize_numerical_indices.html) (read 2026-09-27)
- RapidMiner Studio: [`Equalize Time Stamps`](https://docs.rapidminer.com/latest/studio/operators/modeling/time_series/transformation/equalize_time_stamps.html) (read 2026-09-27)
- RapidMiner Studio: [`Exponential Smoothing`](https://docs.rapidminer.com/latest/studio/operators/modeling/time_series/transformation/exponential_smoothing.html) (read 2026-09-27)
- RapidMiner Studio: [`Extract Coefficients (Polynomial Fit)`](https://docs.rapidminer.com/latest/studio/operators/modeling/time_series/feature_extraction/extract_polynomial_coefficients.html) (read 2026-09-27)
- RapidMiner Studio: [`Extract Peaks`](https://docs.rapidminer.com/latest/studio/operators/modeling/time_series/feature_extraction/extract_peaks.html) (read 2026-09-27)
- RapidMiner Studio: [`Fast Fourier Transformation`](https://docs.rapidminer.com/latest/studio/operators/modeling/time_series/transformation/fast_fourier_transformation.html) (read 2026-09-27)
- RapidMiner Studio: [`Highest Peak Transformation`](https://docs.rapidminer.com/latest/studio/operators/modeling/time_series/transformation/highest_peak_transformation.html) (read 2026-09-27)
- RapidMiner Studio: [`Integrate`](https://docs.rapidminer.com/latest/studio/operators/modeling/time_series/transformation/integration.html) (read 2026-09-27)
- RapidMiner Studio: [`Rainflow Matrix`](https://docs.rapidminer.com/latest/studio/operators/modeling/correlations/rainflow_matrix.html) (read 2026-09-27)
- RapidMiner Studio: [`STL Decomposition`](https://docs.rapidminer.com/latest/studio/operators/modeling/time_series/decomposition/stl_decomposition.html) (read 2026-09-27)
- RapidMiner Studio: [`Z-Score Peak Transformation`](https://docs.rapidminer.com/latest/studio/operators/modeling/time_series/transformation/z_score_peak_transformation.html) (read 2026-09-27)
- Tableau Prep: [`New Rows`](https://help.tableau.com/current/prep/en-us/prep_new_rows.htm) (read 2026-09-27)
