Skip to content
Tutorials Center
My learning

Topics

Lesson 64 of 76 ยท Projects

Project: Sales Dashboard and Forecast

Build a sales dashboard and a six-month forecast in Python: aggregate orders, find seasonality, backtest simple models, draw an uncertainty band, write the summary.

Almost every company wants to know two things about sales: "How are we doing?" and "What happens next?" This project answers both on a synthetic retail company. You will aggregate daily orders into a small dashboard, find the seasonal pattern, compare forecasting methods by backtesting (pretending to forecast the past, where the answer is known), and produce a six-month forecast with an honest uncertainty band and a short written summary.

Forecasting is where simple methods are hard to beat, and where overconfidence is common. So the project follows one rule: a forecast is only worth showing if it beats a naive baseline in a fair test, and it is only honest if it shows how wrong it might be. The methods come from Trends, Seasonality and Time Patterns and Forecasting Basics; the pandas lessons on resampling and time series cover the mechanics.

flowchart LR
    A["Daily orders"] --> B["Aggregate to<br/>monthly revenue"]
    B --> C["Dashboard:<br/>level, trend, growth"]
    B --> D["Seasonality:<br/>decomposition"]
    D --> E["Backtest<br/>3 methods"]
    E --> F["Final forecast<br/>+ uncertainty band"]
    F --> G["Written summary"]

From raw daily data to a forecast someone can plan with.

Step 1: Aggregate and build the dashboard

The data covers January 2022 to December 2024: daily revenue for three regions. It has a rising trend, a yearly seasonal pattern with a strong end-of-year peak, a weekly rhythm (weekends are busier) and random noise. As in real data, the regions have different sizes.

A dashboard is a small number of numbers and charts that answer recurring questions. Ours shows revenue per month by region, the headline figures for the latest year, and the year-over-year growth.

Python Step 1: monthly revenue by region and year-over-year growth

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The headline numbers: total revenue grew from about 1.00 million in 2022 to 1.15 million in 2023 (14.6%) and 1.31 million in 2024 (13.9%), and North brings in 46% of 2024 revenue. Two cautions about this dashboard. Comparing a month with the same month a year earlier (the bottom chart) removes the seasonal pattern; comparing it with the previous month would show December as a "great" month and January as a "collapse" every year. Second, the stacked area chart is good for the total and poor for comparing the regions' individual shapes, because only the bottom layer sits on a flat baseline. If the regions' patterns matter, use small multiples instead (see Matplotlib for Analysts).

Step 2: Find the seasonality

Before forecasting, decompose the monthly total into trend, seasonal and remainder parts. We use a multiplicative model because the seasonal swing grows as sales grow (a 30% December peak on a bigger base is a bigger number).

Python Step 2: trend, seasonal index and weekly rhythm

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The seasonal index says how much a typical month sits above or below an average month. The year-end peak is the dominant feature (December 1.27 times an average month, November 1.23), February is the weakest month at 0.80, and Saturdays and Sundays bring in 25% more than a Monday. The weekly pattern matters for daily planning (staffing, stock), but when we forecast monthly totals it mostly averages out; we only need to remember that months with five weekends are slightly richer. The trend line is smooth and rising, which tells us a model must be able to handle growth as well as seasonality.

Notice that the trend has no values at the very start and end of the series. A centered moving average needs data on both sides, so the decomposition cannot say where the trend is heading now, which is exactly the part forecasting needs.

Step 3: Backtest three methods

Which method deserves to produce our forecast? We answer by rolling-origin backtesting. At each of many past dates (the "origin"), we pretend we only know the history up to that date, forecast the next three months, and compare with what really happened. Every forecast is made without peeking, and we collect many errors instead of relying on one lucky or unlucky holdout.

The three candidates, from simplest to most flexible:

  1. Naive: next month equals this month. A baseline everything must beat.
  2. Seasonal naive: each month equals the same month last year. Very strong for strongly seasonal data.
  3. Holt-Winters (exponential smoothing) with an additive trend and multiplicative seasonality, fitted on the history at each origin.
Python Step 3: rolling-origin backtest of three methods

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Read the table like a referee. Naive and seasonal naive tie at a MAPE (mean absolute percentage error) of 12.7%, but for opposite reasons. Naive ignores the seasonal swing, and its error grows with the horizon (9.1% one month ahead, 14.8% three months ahead). Seasonal naive knows the season but not the growth: when sales grow 14% a year, "same as last year" is always too low, so its error stays at about 12% at every horizon. Holt-Winters models level, trend and season together and is wrong by only 2.8% on average, more than four times better than either baseline.

With only 36 months of history there are just 10 forecast origins (we need 24 months to start), so differences of a few tenths of a percentage point between methods would not be trustworthy. We pick Holt-Winters because it wins by a huge margin, not because of the decimals. If the margin were small we would choose the simpler seasonal naive method.

Step 4: The final forecast with an uncertainty band

Now fit Holt-Winters on all 36 months and forecast January to June 2025. A single line would look more certain than it is. Instead, simulate many possible futures from the fitted model's own error behavior and show the range that contains 80% of them. The band says "plan for this range", not "the answer is exactly this".

Python Step 4: six-month forecast with an 80% band, and the written summary

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The forecast keeps the shape of the year: a high January, a dip in February and a gradual climb through spring. For the first half of 2025 it expects about 0.64 million (80% range 0.62 to 0.67 million), which is 10.9% above the same months of 2024. The band widens as the horizon grows. Treat the band with some care too. It assumes the future behaves like the fitted past (the same growth, the same noise) and it ignores things no model knows, such as a new competitor, a price change or a promotion. A band built from a model is the minimum uncertainty.

Step 5: The written summary

A dashboard without a message is a puzzle. A short note gives the reader the answer first, then the evidence, then the limits:

Sales outlook, first half of 2025. We expect revenue of roughly 0.64 million (80% range 0.62 to 0.67 million), about 11% above the same period of 2024. Revenue grew about 14% in 2024, and the year-end peak (November and December, about 1.25 times an average month) drives the annual pattern; February is the weakest month. We chose Holt-Winters smoothing because, in a rolling backtest of 10 forecast dates, its average error was 2.8%, against 12.7% for both "same as last year" and "same as last month". Caveats: the forecast assumes current growth and seasonality continue; it excludes planned promotions, price changes and new stores. We recommend re-running it monthly and replacing it if the actual figures leave the 80% band several months in a row.

Check every sentence of such a note against the printed numbers before sending it, as you would proofread a contract: wrong figures in a confident paragraph do more damage than a vague one.

Tip: Save the backtest code as a reusable function. Every time a new month of actuals arrives, the same function tells you whether the model is still earning its place against the seasonal naive baseline.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why compare a month with the same month a year earlier instead of the previous month?

    December always beats November in a seasonal business. A year-over-year comparison compares like with like.
  2. 2. What is the main advantage of rolling-origin backtesting over a single holdout?

    Repeating the forecast from many past dates gives many honest errors, which makes the comparison between methods more reliable.
  3. 3. Seasonal naive forecasts 'same month last year'. Why can Holt-Winters beat it on growing sales?

    Last year's value does not include this year's growth. Holt-Winters models level, trend and seasonality together.
  4. 4. What does an 80% forecast band communicate?

    The band is a model-based range. It does not include events the model cannot know about, so reality can fall outside it more often than 20% of the time.
  5. 5. Methods differ by 0.2 percentage points of MAPE in a backtest with 12 origins. What should you conclude?

    With so few origins, small differences are within noise. Choose the simpler method unless another wins by a clear margin.

Summary

  • Aggregate transactions to the grain you need (monthly), and use year-over-year comparisons for seasonal data.
  • Decompose into trend, seasonal and remainder to understand the pattern before forecasting.
  • Always backtest against naive and seasonal-naive baselines using rolling origins; use the simplest method that wins clearly.
  • Show uncertainty: a band from simulation, with the caveat that real-world surprises widen it.
  • Write the summary with the answer first, numbers that match the output, the method choice with its evidence, and the assumptions.
  • Keep the backtest as code so you can re-check the model each month.

Next: Project: Experiment Readout.