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.
| A | B | |
|---|---|---|
| 1 | Known y | Known x |
| 2 | 1 | 0 |
| 3 | 9 | 4 |
| 4 | 5 | 2 |
| 5 | 7 | 3 |
| 6 | ||
| 7 | 2 | 1 |
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.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Month | Sales | Slope | Intercept | |
| 2 | 1 | $3,100 | 1000 | 2000 | |
| 3 | 2 | $4,500 | |||
| 4 | 3 | $4,400 | Month 9 | ||
| 5 | 4 | $5,400 | $11,000 | ||
| 6 | 5 | $7,500 | |||
| 7 | 6 | $8,100 |
=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:
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Month | Sales | Slope | Intercept | SLOPE check | |
| 2 | 1 | $3,100 | 1000 | 2000 | 1000 | |
| 3 | 2 | $4,500 | ||||
| 4 | 3 | $4,400 | ||||
| 5 | 4 | $5,400 | ||||
| 6 | 5 | $7,500 | ||||
| 7 | 6 | $8,100 |
=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:
| A | B | C | |
|---|---|---|---|
| 1 | Row | Column 1 | Column 2 |
| 2 | 1 | 1000 | 2000 |
| 3 | 2 | 133.0950251 | 518.3306538 |
| 4 | 3 | 0.933831377 | 556.7764363 |
| 5 | 4 | 56.4516129 | 4 |
| 6 | 5 | 17500000 | 1240000 |
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
- TREND returns the predicted y-values directly, for a whole range at once.
- CORREL measures how strongly two columns move together.
- Statistics in Excel covers SLOPE, CORREL and the Analysis ToolPak.
- What-if analysis and FORECAST.LINEAR shows one-cell forecasts and Forecast Sheet.
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.