Google Sheets function · Statistical
FORECAST in Google Sheets: syntax and examples
FORECAST fits a straight line through known x and y values and returns the y it predicts for a new x. It is a quick way to project sales, traffic or costs one step ahead. Note that the known y values come before the known x values.
Syntax
FORECAST(x, data_y, data_x)
Arguments
| Argument | Type | Required | What it does |
|---|---|---|---|
x | number | yes | The x value to predict for, such as the next month number. |
data_y | range | yes | The known y values (the thing you predict). Note that y comes before x. |
data_x | range | yes | The known x values, in the same order and count as data_y. |
Examples
The examples use this table, starting in A1:
| Month | Sales |
| 1 | 100 |
| 2 | 120 |
| 3 | 135 |
| 4 | 160 |
| 5 | 178 |
=FORECAST(6, B2:B6, A2:A6)Result: 197.4
Sales expected in month 6, from a straight line through months 1 to 5.
Run in a Google Sheet (English US locale) on .
=FORECAST(3, B2:B6, A2:A6)Result: 138.6
At the middle month the line passes through the average of the sales.
Run in a Google Sheet (English US locale) on .
=ROUND(FORECAST(8, B2:B6, A2:A6), 1)Result: 236.6
Two months further out, rounded to one decimal.
Run in a Google Sheet (English US locale) on .
=ARRAYFORMULA(FORECAST({6; 7}, B2:B6, A2:A6))Result:
| 197.4 |
| 217 |
Several x values at once, one result under the other.
Run in a Google Sheet (English US locale) on .
=ROUND(SLOPE(B2:B6, A2:A6) * 6 + INTERCEPT(B2:B6, A2:A6), 1)Result: 197.4
The same prediction written with SLOPE and INTERCEPT.
Run in a Google Sheet (English US locale) on .
Common errors
- The order is FORECAST(x, data_y, data_x): y first. Swapping the two ranges gives no error, only a different and wrong prediction.
- data_y and data_x must have the same count of values. A mismatch returns #N/A.
- If every x is the same, no line can be drawn and the result is #DIV/0!.
- The model is one straight line. Seasonal or curved data does not fit it, so read the result as a rough trend.
Compared with Excel
Same syntax as Excel FORECAST. Excel 2016+ also has FORECAST.LINEAR with the same arguments.