Hornada Español

Least squares method to forecast sales

Least squares is a way of choosing the line that makes the sum of the squares of the differences between the line and what you sold as small as possible. By hand it is calculated with four sums: of x, of y, of x times y and of x squared.

Updated: 2026-11-27

The idea and the steps

  • A line never passes through all the points: each week there is a difference between the line and what sold.
  • Those differences are squared so that the ones above and the ones below do not cancel out, and so that a large error weighs more than a small one.
  • The least squares line is the one that gives the smallest sum of those squares.
  • 1. Make a table with x (the Saturday number) and y (what sold), and add the columns x times y, and x squared.
  • 2. Add up the four columns. With n points: slope b = (n × sum of xy − sum of x × sum of y) over (n × sum of x² − (sum of x)²).
  • 3. Intercept a = (sum of y − b × sum of x) over n.
  • 4. The line is: sales = a + b × x.

An example (invented numbers)

Saturday (x)Conchas sold (y)x times yx squared
11801801
21863724
31955859
419979616
52101,05025
Sums9702,98355

The pieces are invented; the sum of x (1 + 2 + 3 + 4 + 5) is 15 and n is 5. Slope b = (5 × 2,983 − 15 × 970) over (5 × 55 − 15²) = (14,915 − 14,550) over (275 − 225) = 365 over 50 = 7.3 more conchas per Saturday. Intercept a = (970 − 7.3 × 15) over 5 = (970 − 109.5) over 5 = 172.1. The line is sales = 172.1 + 7.3 × x, and for Saturday 6 it gives 172.1 + 7.3 × 6 = 215.9, about 216 pieces.

SaturdaySoldLineDifferenceDifference squared
1180179.40.60.36
2186186.7−0.70.49
3195194.01.01.00
4199201.3−2.35.29
5210208.61.41.96
Sum0.09.10

The sum of the squares is 9.10. Try another line, the one joining the first point with the last (180 on Saturday 1 and 210 on Saturday 5): it gives 0 + 2.25 + 0 + 12.25 + 0 = 14.5, more than 9.10. No other line goes below 9.10; that is what “least squares” means.

What to watch

  • With few points, one odd point moves the line a lot: check where it comes from.
  • A line follows a rise or a fall; it knows nothing of special dates or of a day the bread ran out.
  • Do it by product and by weekday, not with the whole week.
  • Do not extend it many weeks ahead, and compare it with copying the previous Saturday (in the example, 210) or with the average of the last Saturdays.

How Hornada does it

Hornada forecasts each product for each day from the same weekday of recent weeks, with more weight on the recent ones, and learns the special dates from your history. This line is something you can calculate yourself, by hand or in a sheet; it is not a description of Hornada's calculation.

Frequently asked questions

Why are the differences squared?

So that those above the line and those below it do not cancel out, and so that a large error weighs more than a small one.

Do I have to do it by hand?

No: Excel does it with SLOPE and INTERCEPT (PENDIENTE and INTERSECCION.EJE in a Spanish Excel); by hand it helps you understand where the result comes from.

How many points do I need?

With 2 points an exact line passes through them, but it tells you nothing. With 5 to 8 you can calculate it; trust the result little while you have few.

Try the free diagnosisUpload your sales report and see the result right away. No sign-up; the file is not stored.

Get my 30 days free (WhatsApp)

← Hornada