Google Sheets function · Array
TREND in Google Sheets: syntax and examples
TREND fits a line y = m*x + c by least squares to known x and y values, then returns the y values the line gives for new x values. Without new_data_x it returns the fitted values for the known points.
Syntax
TREND(known_data_y, [known_data_x], [new_data_x], [b])
Arguments
| Argument | Type | Required | What it does |
|---|---|---|---|
known_data_y | range | yes | The known y values (the dependent variable). |
known_data_x | range | no | The known x values. If omitted, 1, 2, 3... is used. |
new_data_x | range | no | The x values to predict y for. Defaults to known_data_x. |
b | boolean | no | TRUE (default) fits a line with an intercept. FALSE forces the line through the origin. |
Examples
The examples use this table, starting in A1:
| Month | Sales |
| 1 | 102 |
| 2 | 118 |
| 3 | 141 |
| 4 | 155 |
| 5 | 181 |
=ROUND(TREND(B2:B6,A2:A6,6),2)Result: 197.9
Predicts sales for month 6 from the five known months.
Run in a Google Sheet (English US locale) on .
=ARRAYFORMULA(ROUND(TREND(B2:B6,A2:A6,{6;7}),2))Result:
| 197.9 |
| 217.4 |
Two new x values give two predictions, one under the other.
Run in a Google Sheet (English US locale) on .
=ARRAYFORMULA(ROUND(TREND(B2:B6),1))Result:
| 100.4 |
| 119.9 |
| 139.4 |
| 158.9 |
| 178.4 |
Without known_data_x, x is 1, 2, 3... and you get the fitted value for every point.
Run in a Google Sheet (English US locale) on .
=ROUND(TREND(B2:B6,A2:A6,6,FALSE),2)Result: 249.38
b = FALSE forces the line through zero, so the prediction differs from the first example.
Run in a Google Sheet (English US locale) on .
=ROUND(TREND(B2:B6,A2:A6,A2),2)Result: 100.4
A cell can be the new x. Here month 1 gets a fitted value, not the original 102.
Run in a Google Sheet (English US locale) on .
Common errors
- known_data_y and known_data_x must have the same number of values. Different sizes, such as B2:B6 with A2:A5, return #REF!.
- Text in the y values returns #VALUE!. Only numbers can be fitted.
- With b = FALSE the line is forced through the origin. The predictions change, so use it only when zero x really means zero y.
- With several new x values, or without new_data_x, TREND returns a column of values. The examples wrap it in ROUND to keep the decimals short.
Compared with Excel
Same syntax in Excel.