Statistical function

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])
ArgumentWhat it means
known_y'sRequiredThe values you want to explain or predict (one column or one row).
known_x'sOptionalOne or more columns (or rows) of explanatory values. Defaults to 1, 2, 3, ...
constOptionalTRUE or omitted: calculate the intercept b normally. FALSE: force the line through the origin (b = 0).
statsOptionalTRUE: 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

D2fx=LINEST(B2:B6, A2:A6)
ABCDE
1Ad spend (k)Sales (k)
22415.513730.2260
3452
4558
5770
6979

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

E2fx=LINEST(C2:C7, A2:B7)
ABCDEFG
1KmStopsMinutes
252244.57332.39932.3256
312449
48335
520678
615352
73114

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

D2fx=LINEST(B2:B6, A2:A6, TRUE, TRUE)
ABCDE
1Ad spend (k)Sales (k)
22415.513730.2260
34520.16180.9575
45580.99740.8746
57701160.64183
6979887.70552.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

D2fx=INDEX(LINEST(B2:B6, A2:A6, TRUE, TRUE), 3, 1)
ABCD
1Ad spend (k)Sales (k)
22410.9974
3452
4558
5770
6979

Result: 0.9974

Row 3, column 1 of the statistics block is R², 0.997422 (shown to 4 decimals), the same value RSQ returns.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 18 KB

Common errors and how to fix them

ErrorWhy it happensFix
#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.

LanguageFunction name
CzechLINREGRESE
DanishLINREGR
DutchLIJNSCH
FinnishLINREGR
FrenchDROITEREG
GermanRGP
HungarianLIN.ILL
ItalianREGR.LIN
Norwegian (Bokmål)RETTLINJE
PolishREGLINP
Portuguese (Brazil)PROJ.LIN
Portuguese (Portugal)PROJ.LIN
RussianЛИНЕЙН
SpanishESTIMACION.LINEAL
SwedishREGR
TurkishDOT