Advanced Visualizer

How Moving Averages and Trendlines Are Calculated on GSC Data

The exact calculation logic behind each trendline and moving average option: the SMA formula, the linear regression method, and how GSC data is aggregated first.

This page documents the exact calculation logic used by the Advanced GSC Visualizer extension for each overlay option: how each type is calculated, what happens to the data before the calculation runs, and why the first few data points show no line.

Available Options by Timeframe

The options available in the Trendline / Moving Average dropdown change based on the active chart timeframe:

  • Daily: None, Trendline, 7-day Moving Average, 14-day Moving Average
  • Weekly: None, Trendline, 4-week Moving Average, 8-week Moving Average
  • Monthly: None, Trendline, 3-month Moving Average

Simple Moving Average (SMA)

The extension uses a trailing lookback window. For each data point at position i, it averages the values from i − period + 1 through i (inclusive). The period is the window size: 7, 14, 4, 8, or 3 depending on the selected option and timeframe.

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

For a 7-day moving average: the value at day 7 = average of days 1–7; the value at day 8 = average of days 2–8, and so on. The window always ends at the current date and spans exactly period data points.

Info Why the first rows show no line

A 7-day moving average requires 7 data points before it can produce a value. Data points 1 through 6 return null — the line simply does not start until day 7. This is correct behavior, not an error. The same logic applies to all window sizes: a 14-day average starts at day 14, a 4-week average starts at week 4.

Linear Trendline

The standard trendline uses ordinary least-squares (OLS) linear regression. X values are sequential indices (0, 1, 2, …, n−1). Y values are the actual metric values. The output is a straight line covering every data point in the visible range, showing the overall direction of the data.

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Slope formula: (n·ΣXY − ΣX·ΣY) / (n·ΣX² − (ΣX)²). Intercept formula: (ΣY − slope·ΣX) / n. Unlike the moving average, the trendline always produces a value for every data point — including the first.

How Data Is Aggregated Before Calculation

Both calculations always run on aggregated data, not raw daily rows. When weekly or monthly timeframe is active, the extension groups daily values first:

  • Clicks and Impressions: summed per week or month
  • CTR: recalculated as total clicks ÷ total impressions for the period
  • Position: averaged per period with an inversion so higher chart values = better rankings

This means the period concept is always relative to the active timeframe. A "7-day moving average" in daily mode averages 7 daily data points. A "4-week moving average" in weekly mode averages 4 already-aggregated weekly totals — not 28 individual days.

Which Metric Gets the Overlay

The extension applies the overlay to the first active metric — whichever metric button was activated first. If Clicks and Impressions are both selected and Clicks was enabled first, the trendline targets Clicks. The legend confirms this with a label such as Trendline(clicks) or 7-day Moving Average(impressions).

Tip Targeting a specific metric

To apply the overlay to Impressions instead of Clicks: deactivate all metric buttons, click Impressions first, then enable any other metrics you want visible in the background.

Automatic Reset on Timeframe Change

Switching the chart timeframe (daily / weekly / monthly) automatically repopulates the dropdown with the options valid for that timeframe and resets the selection to None. This prevents a stale selection — such as a 7-day moving average — from persisting in weekly mode where it does not apply. Reselect the option after changing timeframe.