Skip to main content
v2026.11,858 entries · CC-BY 4.0

How to Find a Slope in Excel: SLOPE, LINEST and Trendline

Find a slope in Excel with SLOPE, LINEST or a chart trendline, with a worked example, the intercept formula and fixes for #N/A and #DIV/0!.

Written and maintained by CASRAI Editorial Board

Last updated

To find a slope in Excel, type =SLOPE(known_y's, known_x's) in a blank cell, pointing the first argument at your y (dependent) values and the second at your x (independent) values. Microsoft documents it as returning “the slope of the linear regression line through data points in known_y’s and known_x’s.” The same number can be pulled out of LINEST, and a linear trendline on a chart draws the same kind of best-fit line. This guide works one set of numbers through all three so you can check your own result against it.

What the slope is used for in research

The slope of a line is the change in y for each one-unit change in x (rise over run). In a regression the slope is the regression coefficient for x: it states how much the outcome is predicted to move per unit of the predictor. Calibration curves, dose or time trends and simple predictor-outcome checks all report it. For the vocabulary behind it, see what a regression coefficient is and y-hat, the predicted value on the line.

Where SLOPE is available

SLOPE is a built-in worksheet function, so there is nothing to install. Microsoft’s function page lists it for Excel for Microsoft 365 (Windows and Mac), Excel 2024, Excel 2021 (Windows and Mac), Excel 2019 and Excel 2016. The documentation is on Microsoft Support (see Sources).

How to find a slope in Excel with SLOPE, step by step

This answers the searches “how to calculate slope in Excel”, “how to get slope in Excel” and “how to find the slope in Excel”. The worked data below is the example Microsoft uses on its INTERCEPT page (y: 2, 3, 9, 1, 8; x: 6, 5, 11, 7, 5), so the intercept can be checked against the documentation.

  1. Put the x values in one column (A2:A6 = 6, 5, 11, 7, 5) and the y values in the next (B2:B6 = 2, 3, 9, 1, 8). Both ranges must hold the same number of data points.
  2. Click an empty cell and type =SLOPE(B2:B6,A2:A6). The y range comes first, the x range second.
  3. Press Enter. The cell shows 0.669355 (0.66935…).

Check by hand: the mean of x is 6.8, the mean of y is 4.6, the sum of (x minus mean x)(y minus mean y) is 16.6 and the sum of (x minus mean x) squared is 24.8. Slope = 16.6 / 24.8 = 0.669355.

Intercept and the line equation

What is the formula for calculating the intercept in linear regression?

The intercept is where the fitted line crosses the y-axis, and it follows from the slope: intercept = mean of y minus slope times mean of x. In Excel, =INTERCEPT(B2:B6,A2:A6) does it directly; Microsoft’s own page gives 0.0483871 for this data. By hand: 4.6 minus 0.669355 times 6.8 = 0.0484.

Together the two results give the line y = 0.669355x + 0.0483871. Plugging x = 6 into it predicts y of about 4.06. See how to calculate residuals to compare predictions with the observed values.

How do I calculate the slope of a line?

For two points, divide the change in y by the change in x. For a cloud of points that do not sit on one line, there is no single rise over run, so use the least-squares regression slope, which is what SLOPE returns. In Excel for two points, =(B3-B2)/(A3-A2) is the plain rise-over-run arithmetic and =SLOPE(B2:B3,A2:A3) gives the same result.

Three ways to get the slope in Excel

For one x variable these all describe the same kind of line. Pick whichever fits what you need next. Every method here is built into Excel, so there is nothing extra to buy or install.

Method What you type or add Use it when
SLOPE =SLOPE(known_y's, known_x's) You want one number in a cell. Pairs with INTERCEPT.
LINEST with INDEX =INDEX(LINEST(known_y's,known_x's),1) for slope, =INDEX(LINEST(known_y's,known_x's),2) for intercept You later want LINEST’s other regression statistics (its stats argument).
Linear trendline on a chart Add a trendline to the series and choose the Linear type You want the best-fit line drawn over the points.

The syntax of LINEST is LINEST(known_y's,[known_x's],[const],[stats]). Microsoft’s page shows the INDEX pattern above for a single x variable.

Free alternatives

The same slope can be computed outside Excel. Each entry below follows the tool’s official documentation (checked 2026-10-29). Use the worked data above to confirm you get 0.669355.

Tool What you type What the documentation says
Google Sheets =SLOPE(B2:B6,A2:A6), syntax SLOPE(data_y, data_x) “Calculates the slope of the line resulting from linear regression of a dataset.” Same argument order as Excel: y first, then x.
LibreOffice Calc =SLOPE(B2:B6;A2:A6), syntax SLOPE(DataY; DataX) “Returns the slope of the linear regression line.” DataY is the array or matrix of Y data and DataX the array or matrix of X data. The help page writes arguments separated by semicolons.
R lm(y ~ x) lm “is used to fit linear models”. The fitted coefficients are returned as a named vector in the coefficients component of the result; the slope is the coefficient for x.
Python (NumPy) numpy.polyfit(x, y, 1) “Least squares polynomial fit.” Coefficients come highest power first, so for degree 1 the result is [slope, intercept]. Note the order: x first, then y. NumPy’s page says Polynomial.fit is recommended for new code as it is more numerically stable.

The documentation pages are listed in Sources.

How to find the slope of a graph in Excel

This covers “how to find slope of a graph in Excel”, “how to calculate slope of a graph in Excel” and “how to find slope on a graph in Excel”. The slope of a graph in Excel comes from the data behind it, not from the picture, so the most reliable route is to apply SLOPE to the same x and y ranges the chart plots.

How to show the slope value on an Excel graph

Calculate the value in a cell with =SLOPE(...) next to the chart, so the number stays tied to the data and recalculates when the data changes. To draw the line itself, select the chart, use the Chart Elements button (the green cross button) and select Trendline; Microsoft’s trendline article lists Linear among the types, and its Trendline options page describes the Linear trendline as a way “to create a best-fit straight line for simple linear data sets.” Build the chart first with how to make a scatter plot in Excel, and read the fitted-line output with linear regression on a scatter plot.

Reading the output

A positive slope means y rises as x rises; a negative slope means it falls; a slope near zero means the fitted line is nearly flat. The slope depends on the units of both variables, so state them when you report it. A slope alone does not say how well the line fits: pair it with a fit measure such as the coefficient of determination, and for a confidence interval on the slope see the linear regression calculator guide.

Troubleshooting

#N/A

Microsoft states that if known_y’s and known_x’s are empty or have a different number of data points, SLOPE returns #N/A. Check that both ranges cover the same number of rows.

A slope that is wrong but not an error

The argument order is y first, then x. Swapping them still returns a number: with the worked data above, =SLOPE(A2:A6,B2:B6) returns 0.312030, not 0.669355. It answers a different question (x regressed on y).

Blank cells, text and zeros

Per Microsoft, text, logical values and empty cells in an argument range are ignored, but cells holding the value zero are included. A zero typed as a placeholder for a missing value therefore changes the slope.

#DIV/0! where LINEST returns 0

Microsoft notes that SLOPE and INTERCEPT use a different underlying algorithm from LINEST, which can give different results when the data is undetermined and collinear. Its example: with known_y’s of 0 and known_x’s of 1, SLOPE and INTERCEPT return #DIV/0! while LINEST returns 0. A single point cannot define a slope, so treat that #DIV/0! as a signal about the data.

FAQ

How do I find the slope in Excel quickly?

Use =SLOPE(y_range, x_range) in an empty cell, with y first.

Does the slope from SLOPE match LINEST?

For ordinary data with one x variable, INDEX(LINEST(...),1) is documented as the slope, and Microsoft only flags differences for undetermined, collinear data.

How do I get the intercept as well?

Use =INTERCEPT(y_range, x_range) with the same two ranges, or =INDEX(LINEST(known_y's,known_x's),2).

How do I calculate the slope of a line?

Rise over run for two points, or SLOPE for a set of points. See the section above.

What is the formula for calculating the intercept in linear regression?

Mean of y minus slope times mean of x. See the intercept section above.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about How to Find a Slope in Excel: SLOPE, LINEST and Trendline

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.