Forecasting sales and demand

A good sales forecast for a smaller business rarely needs “AI” in the modern sense. It needs three years of clean monthly numbers, a method that understands seasonality, and honesty about uncertainty. Here is a simple forecast in Python you can run on an export from your own system – and a list of when…

Last checked:

On this pageWhat this page covers
  1. What a simple forecast can – and cannot – do
  2. First: are the numbers right?
  3. The code: Holt-Winters versus "same month last year"
  4. How to read the result
  5. When the forecast is about people
  6. Where AI actually helps with numbers

What a simple forecast can – and cannot – do

It can predict what resembles the past: the Christmas rush, the summer dip, steady growth. That covers a surprising amount: purchasing, staffing, cash flow and the budget for the next six months.

It cannot predict what has never happened: a new product, a new competitor, a campaign, a pandemic or a price rise. There the best “model” is still a person who knows the market. Use the forecast as a starting point, and write down why you deviate from it.

Don’t ask a language model for the numbers. ChatGPT and Claude are good at writing the code and explaining the result, but they don’t compute a forecast from your history by themselves. Let the code do the maths and the model do the explaining.

First: are the numbers right?

A forecast is never better than its inputs. In our own product JaKonto, which pulls data from e-conomic, Billy and Dinero, a report showed a result of +2,555.50 while e-conomic itself showed −7,803.13. The cause was how accounts were read. A forecast built on those numbers would have pointed the wrong way. Always reconcile your export with the accounting system’s own report first.

Our own sales and customer data live in Odoo 19 on PostgreSQL. From Odoo, e-conomic or Shopify you can export revenue per month as a CSV file. That is all the code below needs. Take only amounts and dates – not customer names. Our inbound route into Odoo accepts only whitelisted fields, so end customers’ data never lands in the CRM. The same principle applies here.

The code: Holt-Winters versus “same month last year”

The script reads a CSV with one row per month and needs at least three full years so the season shows. It first tests two methods on the latest year, as if it were twelve months ago: Holt-Winters, which understands trend and seasonality, and the naive “same month last year”. Whichever hits best makes the forecast for the next six months. The test error becomes an uncertainty band.

# pip install pandas statsmodels
# sales.csv: one row per month, e.g. exported from Odoo, e-conomic or Shopify
#   month,revenue
#   2023-01,412000
import pandas as pd
from statsmodels.tsa.holtwinters import ExponentialSmoothing

s = (pd.read_csv("sales.csv", parse_dates=["month"])
       .set_index("month")["revenue"]
       .asfreq("MS"))                                # month start; a missing month is an error, not 0
assert s.notna().all(), "Months are missing in the data"
assert len(s) >= 36, "Use at least 3 full years so the season shows"


def holt_winters(train: pd.Series, h: int) -> pd.Series:
    model = ExponentialSmoothing(train, trend="add", damped_trend=True,
                                 seasonal="mul", seasonal_periods=12).fit()
    return model.forecast(h)


def seasonal_naive(train: pd.Series, h: int) -> pd.Series:
    """Same month last year. The 'clever' model must beat this, or it is not worth it."""
    idx = pd.date_range(train.index[-1] + pd.offsets.MonthBegin(), periods=h, freq="MS")
    return pd.Series(train.iloc[-12:].values[:h], index=idx)


def mape(actual: pd.Series, forecast: pd.Series) -> float:
    return float(((actual - forecast).abs() / actual).mean() * 100)


# 1) Backtest: pretend it is 12 months ago and forecast the latest year
train, test = s.iloc[:-12], s.iloc[-12:]
hw_err = mape(test, holt_winters(train, 12))
naive_err = mape(test, seasonal_naive(train, 12))
print(f"Error last 12 months: Holt-Winters {hw_err:.1f} %, same month last year {naive_err:.1f} %")

# 2) Forecast the next 6 months using the full history
best = holt_winters if hw_err < naive_err else seasonal_naive
fc = best(s, 6)
band = min(hw_err, naive_err) / 100                  # rough band: the chosen model's backtest error
out = pd.DataFrame({"forecast": fc, "low": fc * (1 - band), "high": fc * (1 + band)}).round(-3).astype(int)
print(f"Model: {best.__name__}")
print(out.to_string())

We ran the script on four years of made-up numbers with seasonality and 1 % monthly growth. Holt-Winters missed the latest year by 4.3 % on average, “same month last year” by 11.0 %. On your own numbers it may well be the other way round – which is why the script tests both.

How to read the result

Test errorMeaningWhat to do
under 5 %stable business with a clear seasonuse the forecast for purchasing and staffing
5–15 %useful direction, uncertain single monthsplan with the band, not the middle number
over 15 %the past does not explain the futuredon’t use it alone; ask the people who know the market
naive beats Holt-Wintersthe season is stronger than the trenduse “same month last year” and adjust by hand
Error = mean absolute percentage error (MAPE) when testing on the latest year

When the forecast is about people

A forecast of monthly revenue is not about any particular person. But “which customers will cancel”, “who will pay late” or “which candidates fit” is about individuals. That is profiling, and GDPR has special rules for automated decisions. That is why AI in our own product jajob is advisory only: it gives a score with sources, but never rejects anyone by itself. More on the rules for AI systems at ai-forordning.best-choice.dk.

Where AI actually helps with numbers

Language models are good at sorting and explaining. Our own Odoo module triages the inbox with AI for about $0.0003 per conversation, with a cap of 1 dollar a day. We tested it first on a copy of 93 old conversations for $0.037. An AI bookkeeper and analyst on top of JaKonto is planned, but not live yet. We say so because many sites promise more than exists.

Sources

Last reviewed: 2026-12-03

Questions about forecasts

How many years of data do we need?

At least three full years of monthly numbers, so the model sees the season more than once. With less than two years it cannot tell season from chance.

Should we use Prophet or machine learning instead?

For one monthly revenue series, Holt-Winters and “same month last year” are hard to beat. More advanced methods make sense with many products, daily numbers or known drivers like campaigns and weather.

Can we forecast per product?

Yes, run the script per product or product group. Products with few sales a month give large errors; group them.

What about campaigns and price changes?

The model only sees them as noise. Mark them in the data, or adjust the forecast by hand and write down why.

Fixed price, no commitment

Get a fixed price for AI on your own data

Tell us briefly what you use today and what you want to achieve. A person answers by e-mail with a proposal and a fixed price before any work starts.

  • A fixed price before we start
  • An answer by e-mail, no calls
  • Your details are used only to answer you

Fields marked with * are required.

What is it about?