MedusaJS Plugins / Stats & Analytics/composite-statistics-provider

Composite Statistics Provider

May 1, 2026 · 5 min read

The Composite Statistics Provider is the derived-metrics layer in medusa-stats. It does not query commerce entities directly. Instead, it consumes the output of another statistic and transforms it into a new series.

This is the provider to use when you want rolling averages, rates of change, smoothing, or any other statistic that builds on a previously calculated result.

Available Statistics

Moving Average

  • Identifier: moving_average
  • Description: Smooths a series by averaging values across a rolling window.
  • Parameters:
    • input_series (stat, default []): dependency output to analyze
    • window_size (number, integer, min 2, max 365, default 7): number of points in each rolling window

Rate of Change

  • Identifier: rate_of_change
  • Description: Measures the change between a point and the value N periods back.
  • Parameters:
    • input_series (stat, default []): dependency output to analyze
    • periods (number, integer, min 1, max 365, default 1): lookback distance
    • as_percentage (boolean, default true): return percent change instead of decimal change

Dependency Input Format

The input_series parameter expects a sorted series of points shaped like this:

[
  { x: "2026-05-01T00:00:00.000Z", value: 120 },
  { x: "2026-05-02T00:00:00.000Z", value: 140 }
]

The provider normalizes the series by converting x values into dates and sorting them chronologically before calculation.

How It Works

Composite statistics are only useful when paired with a source statistic. In the UI, that means mapping another statistic option into input_series.

That makes the provider ideal for advanced analytics such as:

  • smoothing sales volatility
  • calculating moving average revenue trends
  • tracking period-over-period growth
  • reducing noise in customer or order metrics

Example Usage

Use a base statistic from the Common Statistics Provider, then feed its result into a composite statistic like moving_average or rate_of_change.

For example, a sales chart can be smoothed with a seven-point moving average, or compared month over month with a rate-of-change statistic.