Skip to content

KPI dashboardsPostgreSQL · Logistics and supply chain

Demand forecast and its error, from sales history on PostgreSQL

Sales history by item and by day often sits in a PostgreSQL database, belonging to the ERP or the warehouse system. This page explains how to derive from it, every night, a forecast with a band, put it next to actual sales and measure how wrong it is, item by item, so whoever reorders knows how far to trust it.

By Muvia · Updated October 22, 2026

The use case: Demand and stock forecasting

The indicators: forecast and error

A forecast without a measure of its error does not help anyone decide. The most used indicators compare forecast and actual once the period is closed; bias says whether the forecast tends to sit above or below.

WAPE = Σ |actual − forecast| ÷ Σ actual

MAPE = average of |actual − forecast| ÷ actual, period by period

Bias = Σ (forecast − actual) ÷ Σ actual

Band = the range where the actual value is expected to fall, with the chosen probability

WAPE is sturdier than MAPE for items that sell very little in some periods. The guide to demand forecasting compares methods and has a forecast error calculator.

What the dashboard shows

  • Forecast against actual sales by item and family, with the band around the forecast.
  • Error by family: WAPE and bias over recent weeks, to know where the forecast can be relied on and where it cannot.
  • Items at risk of running short: those where the forecast for the coming weeks exceeds available stock.
  • Error over time, to notice when a model starts to get worse.

The data you need from the database

DataTypical fieldsWhat it is for
Sales or shipmentsdate, item, quantity, store or customerThe history to forecast from
Itemscode, family, status (active, phasing out, new)Grouping and excluding discontinued items
Stockitem, warehouse, quantityComparing with the forecast
Promotions calendaritem, period, kind of promotionExplaining peaks instead of chasing them

The promotions calendar often lives in an Excel file: it is loaded as a source of its own.

The steps in Muvia

  1. In New source choose PostgreSQL, give the server and a read-only user, and select sales, items and stock. Muvia copies them on the schedule you choose, incrementally and over an encrypted TLS connection.

  2. A query prepares the history at the level you reorder, for example item and week.

  3. A predictor of the Forecast kind is created from that query in four steps (what, from where, when, alarm) and returns the expected value with a band; the ready-made forecast needs no training. If your data scientist already has a model, it is uploaded as a file and tried before it is activated.

  4. A flow applies the forecast every night and writes a forecast table; another query compares it with actual sales and calculates WAPE and bias.

  5. The dashboard shows forecast, actual and band; an alarm flags the items where the forecast exceeds stock.

The pitfalls of sales history

  • Sales are not demand: on days when the item was out of stock, sales were zero but demand was there. Mark those days and do not use them as if they were real demand.
  • Promotions: a promotional peak teaches the model a demand that does not exist without the promotion. The promotions calendar is what separates it.
  • New items: with no history, the forecast leans on the family or on similar items, with a wider band.
  • Level of detail: forecasting by item, day and store is noisier than by family and week. Choose the level by how you reorder.

Frequently asked questions

Not to start: Muvia's ready-made forecast starts from a query and needs no training. If your team already has a model, it is uploaded as a file and Muvia runs it every night next to the data.

Bring us a question you can't answer today.

We start from a real question your business has and walk the path from source to dashboard with your systems, not a demo dataset.