In Excel: use =SLOPE(known_ys, known_xs) and =INTERCEPT(known_ys, known_xs) — together they give the two coefficients of the best-fit straight line, y = slope × x + intercept.
On this page8
Syntax
Arguments
| Argument | required / optional | Description |
|---|---|---|
known_ys | required | The dependent values — the thing being predicted. |
known_xs | required | The independent values, the same size as known_ys. |
Related functions
Select a cell for the slope and type =SLOPE(.
Select the y values (the outcome) FIRST, then a comma, then the x values.
Repeat in a second cell with =INTERCEPT and the same argument order.
Combine them as intercept + slope × x to predict any new value.
What this does
SLOPE and INTERCEPT return the two numbers that define the least-squares regression line through a set of points. SLOPE is the rate of change — how much y moves per unit of x — and INTERCEPT is where the line crosses at x = 0. Written out they reproduce exactly the trendline equation a chart displays, which makes them the way to use a fitted line in calculations rather than merely look at one. Watch the argument order: the y values come first, which is the reverse of how most people say "x against y". Keep the inputs visible and clearly labelled and the whole thing stays auditable — anyone who opens the file later, including you, can see at a glance exactly what feeds the result and change one assumption without hunting through the formula. The difference between a quick fix and a sheet you can trust is the extra minute you spend validating “calculate slope of a graph in excel”. Start on a copy or a tiny sample, keep the affected chart visible, and compare the result with the tool above before you touch the real workbook. When a formula is involved, keep the inputs labelled beside it, reference cells instead of typing values, and apply number formatting only after the result checks out. The point is a visual that makes the number obvious at a glance, but the practical win is that someone else can open the file and understand what happened without asking you.
A worked example
Units produced in B2:B40 and total cost in C2:C40: =SLOPE(C2:C40, B2:B40) returns the variable cost per unit and =INTERCEPT(C2:C40, B2:B40) the fixed cost. Predicting the cost of 250 units is then =INTERCEPT(...) + SLOPE(...)*250, which is what FORECAST.LINEAR does in a single call. SLOPE and INTERCEPT take a chart trendline out of the picture and put it into the model, where it can drive actual calculations. If there is any chance you will reuse this, drop it into a small template tab right now: a labelled input area on the left and the formula beside it, checked once against the tool above. Next time the same question comes up, the answer is a single paste away instead of a rebuild from memory.
In Google Sheets
Everything above works in Google Sheets too. Excel and Sheets share the formula syntax used here; only the surrounding menus are arranged differently. That portability is deliberate — learn it once and it follows you between the two tools and across Windows and Mac. Nothing on this page is behind a login or a download: the exact answer is at the top, and the detail below it is there for when you need it. That is the whole promise here — the answer first, and just enough context to make it stick. The short version of “calculate slope of a graph in excel”: the answer is at the top of this page, the tool proves it on your own numbers, and the sections above explain why it holds so the next variation does not stump you. Excel rewards people who reference cells instead of typing values and who keep inputs separate from formulas, because that is what makes a result you can audit months later. Build it once, deliberately, with the live tool as a check, and you convert a one-off lookup into a reusable skill — which is the whole point of learning the why and not just the what.
Common mistakes
- Reversing the arguments — y comes first in both functions, and swapping them silently returns a different line.
- Extrapolating far beyond the observed x range, where a straight line has no support from the data.
- Fitting a line to plainly curved data; check the scatter plot before trusting either coefficient.
Frequently asked questions
Which argument comes first?
The y values — the thing being predicted. =SLOPE(known_ys, known_xs).
How do I get the trendline equation from a chart into cells?
SLOPE and INTERCEPT return exactly those two coefficients, so you can use the fitted line in formulas instead of reading it off the chart.
How do I predict a value?
=INTERCEPT(ys,xs) + SLOPE(ys,xs)*newX, or the shorter =FORECAST.LINEAR(newX, ys, xs).