LINEST function
Fits a straight line (or a multiple regression) by least squares and returns the coefficients, plus optional statistics.
Available in All versions of Excel, including Microsoft 365 and Excel for the web (spills automatically in Microsoft 365 and Excel 2021+; earlier versions need Ctrl+Shift+Enter)
In every Excel versionWorks in Google Sheets
Syntax
LINEST(known_y's, [known_x's], [const], [stats])| Argument | What it means | |
|---|---|---|
known_y's | Required | The values you want to explain or predict (one column or one row). |
known_x's | Optional | One or more columns (or rows) of explanatory values. Defaults to 1, 2, 3, ... |
const | Optional | TRUE or omitted: calculate the intercept b normally. FALSE: force the line through the origin (b = 0). |
stats | Optional | TRUE: return a 5-row table of regression statistics. FALSE or omitted: return only the coefficients. |
Returns: An array: the coefficients mₙ, …, m₁, b in one row, and with stats four more rows of statistics.
How LINEST works
LINEST is Excel's regression engine in one formula. With one x column it finds the same best-fit line as SLOPE and INTERCEPT, returning both numbers side by side. With several x columns it runs a multiple regression, for example explaining delivery time from distance and number of stops at the same time, and returns one coefficient per x plus the intercept. Each coefficient tells you how much y changes when that x rises by one unit while the others stay fixed.
Two details trip everyone up. First, the coefficients come back in reverse column order: for x columns A and B the output is {m_B, m_A, b}. Second, with stats set to TRUE you get a 5-row block: row 1 coefficients, row 2 their standard errors, row 3 R² and the standard error of the estimate, row 4 the F statistic and the residual degrees of freedom, row 5 the regression and residual sums of squares. Cells that have no meaning in rows 3–5 (beyond the first two columns) show #N/A. Use INDEX to pick out a single number, e.g. =INDEX(LINEST(y,x),1) for the slope.
Examples
1Slope and intercept in one go
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Ad spend (k) | Sales (k) | |||
| 2 | 2 | 41 | 5.5137 | 30.2260 | |
| 3 | 4 | 52 | |||
| 4 | 5 | 58 | |||
| 5 | 7 | 70 | |||
| 6 | 9 | 79 |
The result spills into D2:E2: slope 5.513699 and intercept 30.226027 (shown to 4 decimals). Every extra 1k of advertising goes with about 5.51k more sales.
2Multiple regression: distance and stops
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Km | Stops | Minutes | ||||
| 2 | 5 | 2 | 24 | 4.5733 | 2.3993 | 2.3256 | |
| 3 | 12 | 4 | 49 | ||||
| 4 | 8 | 3 | 35 | ||||
| 5 | 20 | 6 | 78 | ||||
| 6 | 15 | 3 | 52 | ||||
| 7 | 3 | 1 | 14 |
Note the reversed order: E2 is the coefficient for Stops (4.5733 minutes per stop), F2 for Km (2.3993 minutes per km), G2 the intercept (2.3256). All shown to 4 decimals. A 10 km route with 3 stops is estimated at about 40 minutes.
3Full regression statistics
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Ad spend (k) | Sales (k) | |||
| 2 | 2 | 41 | 5.5137 | 30.2260 | |
| 3 | 4 | 52 | 0.1618 | 0.9575 | |
| 4 | 5 | 58 | 0.9974 | 0.8746 | |
| 5 | 7 | 70 | 1160.6418 | 3 | |
| 6 | 9 | 79 | 887.7055 | 2.2945 |
A 5 × 2 block (shown to 4 decimals). Row 1: slope, intercept. Row 2: their standard errors. Row 3: R² = 0.9974 (the line explains 99.7% of the variation) and the standard error of y. Row 4: F statistic and degrees of freedom (n − 2 = 3). Row 5: regression and residual sums of squares.
4Pick one statistic with INDEX
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Ad spend (k) | Sales (k) | ||
| 2 | 2 | 41 | 0.9974 | |
| 3 | 4 | 52 | ||
| 4 | 5 | 58 | ||
| 5 | 7 | 70 | ||
| 6 | 9 | 79 |
Result: 0.9974
Row 3, column 1 of the statistics block is R², 0.997422 (shown to 4 decimals), the same value RSQ returns.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#REF! | known_x's and known_y's do not line up (different number of rows). | Use ranges with the same number of observations. |
#VALUE! | A cell in the ranges is empty or text. Unlike SLOPE, LINEST does not skip them. | Clean the data or remove blank rows; use FILTER to pass only complete rows. |
#SPILL! | The output area is not empty. | Clear the cells to the right (and below, with stats). |
Tips
- Remember the reverse order: the last x column's coefficient comes first.
- If two x columns are almost copies of each other (collinear), Excel drops one and shows 0 for its coefficient; check the standard errors.
- To use a polynomial, pass powers as columns:
=LINEST(y, x^{1,2})fits y = m₂x² + m₁x + b.
Questions
Why are my LINEST coefficients in the wrong order?
They are not wrong, just reversed: LINEST lists the coefficient for the last x column first and the intercept last.
How do I get a p-value for a coefficient?
Divide the coefficient by its standard error (row 2) to get t, then use =T.DIST.2T(ABS(t), df) with the degrees of freedom from row 4, column 2.
Google Sheets
LINEST also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.
LINEST in other languages
In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.
| Language | Function name |
|---|---|
| Czech | LINREGRESE |
| Danish | LINREGR |
| Dutch | LIJNSCH |
| Finnish | LINREGR |
| French | DROITEREG |
| German | RGP |
| Hungarian | LIN.ILL |
| Italian | REGR.LIN |
| Norwegian (Bokmål) | RETTLINJE |
| Polish | REGLINP |
| Portuguese (Brazil) | PROJ.LIN |
| Portuguese (Portugal) | PROJ.LIN |
| Russian | ЛИНЕЙН |
| Spanish | ESTIMACION.LINEAL |
| Swedish | REGR |
| Turkish | DOT |