Thanks to @cwindolf for the main leg work on this.
This is how I was able to get it to be exactly the same as their trendline.
It consists of 3 parts.
- the start value from the original data series
- a 2 month moving average
- forecasting using simple linear regression
1. Start value
We simply just use the same value from original the series
C0=B0
2. 2 month moving average
Average y values from the same index as the original series, and the index before it
Ci=AVERAGE(B(i-1):Bi)
(thanks to @cwindolf)
3. forecasting using simple linear regression
We'll be using this formula to calculate our $y$
$$
y=\alpha +\beta x
$$
where $\alpha$ is
$$
\alpha =\bar{y}-\beta \bar{x}
$$
and $\beta$ is
$$
\beta=\frac{\sum(x_{i}-\bar{x})(y_{i}-\bar{y})}{\sum(x_{i}-\bar{x})^{2}}
$$
Google Sheet's formula for C5
's $\beta$ is =SUM(ARRAYFORMULA((A3:A4-AVERAGE(A3:A4))*(B3:B4-AVERAGE(B3:B4)))) / SUM(ARRAYFORMULA((A3:A4-AVERAGE(A3:A4))^4))
and the formula for C5
's $\alpha$ with $\beta$ subbed in is =SUM(ARRAYFORMULA((A3:A4-AVERAGE(A3:A4))*(B3:B4-AVERAGE(B3:B4)))) / SUM(ARRAYFORMULA((A3:A4-AVERAGE(A3:A4))^2))
bringing it all together for C5
($y$) we get
=AVERAGE(C3:C4)-(SUM(ARRAYFORMULA((A3:A4-AVERAGE(A3:A4))*(C3:C4-AVERAGE(C3:C4)))) / SUM(ARRAYFORMULA((A3:A4-AVERAGE(A3:A4))^2))*AVERAGE(A3:A4))+(SUM(ARRAYFORMULA((A3:A4-AVERAGE(A3:A4))*(C3:C4-AVERAGE(C3:C4)))) / SUM(ARRAYFORMULA((A3:A4-AVERAGE(A3:A4))^2))*A5)
To see it in action and to see a breakdown check out the SOLUTION
sheet in this google sheet
Ci
has valueAVG(B(i-3):B(i-1)
. What if you just didCi=AVG(B(i-2):Bi)
(i.e. move your C-column up by one step)? The choice of Period=2 in the screenshot you show might also indicate that you should use a 2-month moving average to replicate Google. $\endgroup$