Skip to content

Lesson 65 of 92 · Free Excel Course

Excel · Excel function reference

Excel LINEST Function: Syntax, Examples and Common Errors

How the Excel LINEST function finds the slope and intercept of a best-fit line, reads the stats table, and predicts values. Free practice workbook.

The Excel LINEST function finds the straight line that best fits a set of points and tells you its slope and intercept. Give it the numbers you want to explain (the y-values, such as sales) and the numbers that might explain them (the x-values, such as months), and it returns two numbers side by side: how much y goes up for each step in x, and where the line starts when x is 0. Set one extra argument and it also reports how good the fit is. LINEST works in Excel for Microsoft 365 (Windows and Mac), Excel for the web, Excel 2024, 2021, 2019 and 2016.

A straight line is written y = mx + b. m is the slope: if m is 1,000, every extra month adds about 1,000 in sales. b is the intercept: the value of y when x is 0. Real data never sits exactly on a line, so LINEST uses the least squares method: it picks the line that makes the squared gaps between each point and the line as small as possible.

Syntax

=LINEST(known_y's, [known_x's], [const], [stats])
  • known_y's (required): the y-values you already have, such as a column of sales.
  • known_x's (optional): the matching x-values. If you leave it out, Excel uses 1, 2, 3 and so on, one for each y-value. With one x column, the two ranges must be the same size. You can give several x columns side by side (multiple regression); then known_y's must be a single column or row.
  • const (optional): TRUE or left out calculates the intercept b normally. FALSE forces b to 0, so the line goes through the origin.
  • stats (optional): FALSE or left out returns only the slope(s) and the intercept. TRUE adds the regression statistics described below.

The result comes back in reverse order of the x columns: {mn, ..., m1, b}. With one x column that is simply slope, then intercept.

Entering it: in Microsoft 365, Excel 2021, Excel 2024 and Excel for the web, type it in one cell and press Enter; the answer spills into the cells to the right (and below, with stats). In Excel 2019 and 2016, select the whole output range first (two cells side by side for the basic version), type the formula and press Ctrl+Shift+Enter to enter it as an array formula.

Examples

Example 1 (Microsoft's own): four points with the y-values in column A and the x-values in column B.

A7=LINEST(A2:A5,B2:B5,,FALSE)
AB
1Known yKnown x
210
394
452
573
6
721
The slope (2) lands in A7 and the intercept (1) spills into B7. The empty third argument keeps const at its default; the FALSE is stats.

All four points sit exactly on y = 2x + 1, so the slope is 2 and the intercept is 1. Note the double comma: the empty third argument means "calculate the intercept normally". The FALSE belongs to stats, not const.

Example 2 (Microsoft's own): predict a future month. Microsoft's page lists sales for months 1 to 6 and estimates month 9. Here the data has a header row, so it sits in A2:B7.

D5=SUM(LINEST(B2:B7,A2:A7)*{9,1})
ABCDE
1MonthSalesSlopeIntercept
21$3,10010002000
32$4,500
43$4,400Month 9
54$5,400$11,000
65$7,500
76$8,100
=LINEST(B2:B7,A2:A7) in D2 spills 1000 and 2000. The month-9 formula multiplies them by 9 and 1 and adds them up.

=LINEST(B2:B7,A2:A7) says sales rise by 1,000 a month from a starting point of 2,000. To forecast month 9, {9,1} multiplies the slope by 9 and the intercept by 1, and SUM adds the two: 9 × 1,000 + 2,000 = $11,000. To forecast a whole list of months, TREND does the same in one step.

Example 3: pull out one value with INDEX. When you need the slope in a single cell (to use in another formula), wrap LINEST in INDEX. With the same sales data:

D2=INDEX(LINEST(B2:B7,A2:A7),1)
ABCDEF
1MonthSalesSlopeInterceptSLOPE check
21$3,100100020001000
32$4,500
43$4,400
54$5,400
65$7,500
76$8,100
E2 uses =INDEX(LINEST(B2:B7,A2:A7),2). F2 is =SLOPE(B2:B7,A2:A7), which agrees.

=INDEX(LINEST(B2:B7,A2:A7),1) returns the slope and ,2) returns the intercept, and neither spills. If one number is all you need, SLOPE and INTERCEPT are simpler and give the same answers for one x column.

Example 4: the statistics table (stats = TRUE). =LINEST(B2:B7,A2:A7,TRUE,TRUE) on the same six months returns five rows and two columns:

ABC
1RowColumn 1Column 2
2110002000
32133.0950251518.3306538
430.933831377556.7764363
5456.45161294
65175000001240000
Row 1: slope, intercept. Row 2: their standard errors. Row 3: r² and the standard error of the y estimate. Row 4: F statistic, degrees of freedom. Row 5: regression and residual sums of squares.

What each cell means, in plain words:

  • Row 1: the slope (m) and the intercept (b), as before.
  • Row 2: the standard error of each. Small compared with row 1 means the value is pinned down well.
  • Row 3: r² (0.93 here: the line explains about 93% of the ups and downs in sales) and sey, the typical miss of a prediction, about $557.
  • Row 4: the F statistic and the degrees of freedom (6 points minus 2 = 4). They are used to test whether the relationship is real or chance.
  • Row 5: ssreg, the variation the line explains, and ssresid, what's left over. r² = ssreg ÷ (ssreg + ssresid) = 17,500,000 ÷ 18,740,000.

You can check these yourself: RSQ gives 0.933831377 and the six misses (100, 500, −600, −600, 500, 100) squared and added give 1,240,000. With several x columns, row 1 holds one slope per column, last column first, and the table gets wider. Microsoft's own multiple-regression example (office value from floor space, offices, entrances and age) reports an r² of 0.996747993.

Common errors

  • Only the slope shows. The second cell is covered (#SPILL! in newer Excel) or, in Excel 2019/2016, you entered it in one cell. Clear the cells to the right, or select two cells and use Ctrl+Shift+Enter.
  • #SPILL! Something is in the way of the output range. With stats TRUE you need 5 empty rows.
  • #VALUE! A range contains text or blank cells, often because the header row was included. Select only the numbers.
  • #REF! The y and x ranges are different sizes. Make them the same length.
  • #N/A in the stats table. With one x column, rows 3 to 5 have values in column 2, but a wider table can show #N/A in cells that have nothing to report. Also, with const FALSE the intercept's standard error is #N/A. Both are normal.
  • Slope and intercept swapped. The order is slope first, intercept last. With several x columns, the first value belongs to the last x column.
  • Wild predictions. Microsoft warns that predictions can be invalid outside the range of your data. A line through months 1 to 6 says little about month 60.

Related functions

Try it yourself

Download the practice workbook. It has six days of temperatures and ice-cream sales: fit the line with LINEST, pull out the slope and intercept with INDEX, check them with SLOPE, predict sales on a 90°F day and read r² from LINEST's own stats table. The Answers sheet has working formulas, including the full stats table above as a live LINEST formula.

Frequently asked questions

Why does LINEST only show one number?

LINEST returns at least two values (slope, then intercept). In Microsoft 365, Excel 2021 and Excel 2024 it spills them into the cells to the right, so make sure those cells are empty. In Excel 2019 or 2016, select two side-by-side cells first, type the formula and press Ctrl+Shift+Enter, or you only see the slope.

What is the difference between LINEST and SLOPE?

For one set of x-values they give the same slope. SLOPE returns just that one number, so it's easier. LINEST also returns the intercept, can take several x columns at once, and with stats set to TRUE adds r², standard errors and the F statistic.

How do I get just the slope or just the intercept from LINEST?

Wrap it in INDEX. With one x column, =INDEX(LINEST(B2:B7,A2:A7),1) returns the slope and =INDEX(LINEST(B2:B7,A2:A7),2) returns the intercept. This is the method Microsoft gives on its LINEST page.

How do I read R-squared from LINEST?

Set the fourth argument to TRUE. With one x column the result is 5 rows by 2 columns, and r² is the first cell of row 3. It runs from 0 to 1; the closer to 1, the better the straight line fits your points. =RSQ(known_y's,known_x's) gives the same number on its own.