
📎 This article includes 1 downloadable practice file ↓
The simplest machine-learning model is a straight line through your data. Excel can fit it with plain formulas — no Analysis ToolPak needed.
In this article
Example: ad spend vs sales
Put monthly ad spend in B2:B25 (x) and sales in C2:C25 (y).
=SLOPE(C2:C25, B2:B25) ' extra sales for each extra ₹1 of ads
=INTERCEPT(C2:C25, B2:B25) ' predicted sales with zero ad spend
=RSQ(C2:C25, B2:B25) ' 0-1: how much of the variation the line explains
=FORECAST.LINEAR(50000, C2:C25, B2:B25) ' predicted sales at ₹50,000 spend
LINEST: everything at once
=LINEST(C2:C25, B2:B25, TRUE, TRUE)
In Excel 365 this spills a 5×2 block of statistics: slope and intercept in the first row, their standard errors in the second, R² in the third, then the F statistic and sums of squares. For several inputs (ad spend and discount %), pass a multi-column x range: =LINEST(D2:D25, B2:C25, TRUE, TRUE). Note that LINEST returns the coefficients in reverse column order.
Reading the result sensibly
- R² of 0.8 means the line explains 80% of the ups and downs — it does not prove ads cause sales.
- Predict only inside the range you have data for. A line fitted on ₹10k–₹60k spends says nothing reliable about ₹5 lakh.
- Always chart it: Insert → Scatter, then Add Trendline → Display equation and R². One outlier can drag the whole line.
TREND returns fitted values for a whole column at once — =TREND(C2:C25, B2:B25) — handy for a “predicted vs actual” chart.Want to see how the computer actually finds that line? Read linear regression from scratch in Python.
📎 Practice files for this article
- 📄All code from this post2 examples in one file, ready to open in your editor.⬇ TXT · 624 B
Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.
Atul (AJ) builds office-automation and local-first AI tools as Atulya AI, and works with Excel, SAP and Oracle EPM every day. He writes about the shortcuts, macros and automations that actually save time — plus the occasional wacky fact. Videos on YouTube: Lazy Automator AI (@LazyAutomatorAI).
More posts by Atul →Stuck on a step? Ask a question and the AI answers using this article.