A shop records 10 orders every day except one Wednesday, when it receives 80. Its trailing seven-day average rises to 20 orders per day on Wednesday and stays there through the following Tuesday. One busy day has lifted seven consecutive averages.

These are original hypothetical counts, with a known total for every calendar day. The record includes the six days before the busy Wednesday and the seven days after it. Each trailing window includes its ending day and the six days immediately before it.

Daily orders are 80 on the highlighted Wednesday and 10 afterward. The trailing seven-day mean is 20 from that Wednesday through Tuesday, then returns to 10 the next Wednesday when the spike leaves the window.
The seven raised means all include the same 80-order Wednesday. The next Wednesday’s window contains seven 10-order days.Credit: MathBlog

Find the extra orders in the first window

Seven ordinary days would contain \(7\times10=70\) orders. Replacing one 10-order day with an 80-order day adds 70 orders, bringing the seven-day total to 140.

\[\frac{80+6\times10}{7}=\frac{140}{7}=20\text{ orders per day}.\]

Equivalently, the spike adds \(70\div7=10\) to the ordinary mean of 10. The average spreads that extra count across the seven days in the window.

Slide the window one day at a time

Thursday’s window drops the previous Thursday’s 10 orders and adds the new Thursday’s 10 orders. The busy Wednesday is still inside. The total remains 140, and the mean remains 20.

The same exchange occurs on Friday, Saturday, Sunday, Monday, and Tuesday. Only the endpoints of the window change; its one 80-order day remains included.

Eight complete seven-day windows around the busy Wednesday
Window ends Window begins Total orders Orders per day
Wednesday, the spike Thursday before the spike 140 20
Thursday after Friday before the spike 140 20
Friday after Saturday before the spike 140 20
Saturday after Sunday before the spike 140 20
Sunday after Monday before the spike 140 20
Monday after Tuesday before the spike 140 20
Tuesday after Wednesday, the spike 140 20
Next Wednesday Thursday after the spike 70 10

On the next Wednesday, the 80-order day finally leaves the window. A 10-order day replaces it. The total falls by 70, from 140 to 70, and the mean falls from 20 to 10.

Look at the observations behind the smooth line

Seven raised points do not mean the shop had seven busy days. The underlying record contains one 80-order day. Adjacent averages reuse six of their seven daily counts.

The averaging rule explains how long that one event remains visible. With equally weighted, complete seven-day windows, an individual day’s count belongs to seven consecutive window endings. A different window length would change that span.

In symbols, if \(x_t\) is the order count on day \(t\), the trailing mean is:

\[\overline{x}_t=\frac{x_t+x_{t-1}+\cdots+x_{t-6}}{7}.\]

For this dataset, compare each reported mean with the dates included in its numerator. That identifies the one spike without treating each overlapping window as a separate event.

Check that every day is known

This example assumes complete daily records. An absent report cannot automatically supply a count of 10 or zero. See why a missing day differs from a zero-sales day before filling gaps in a real series.

For a software example, our pandas rolling-average tutorial shows how row and elapsed-time windows can select different observations.

Further reading