Probabilistic Demand Forecasting in Excel
A probabilistic demand forecast assigns a probability to every quantity customers might want, including zero. A buyer ordering for several months also needs to know how demand in those months is related. Two forecasts can agree on the average for May and the average for June, yet disagree about the value of one more case before summer.
Download the Excel workbook (.xlsx). It opens on Guide. Each link takes you to a worksheet, and the tabs follow the calculation from sales records to a purchase order. Blue cells hold the inputs. The example uses ordinary Excel formulas and needs no macros or add-ins.
The order
A parts counter has 24 pool-filter cartridges on May 1. Its next regular shipment arrives July 1. The supplier offers express delivery before the first May sale, at $9 extra per case of six. The counter may take up to six cases. Each sale that would otherwise be lost earns $10 after the ordinary cost of the cartridge. Unsold cartridges keep their value for July. The only extra cost in this example is the express freight.
Should the counter take the fourth case? The first three bring stock to 42. The fourth pays for itself if enough customers want cartridges 43 through 48. Both forecasts in the workbook put average demand through June at 37.7. To see why one recommends buying that fourth case, start with what the counter actually measured.
1. Which months measured demand? (History)
Open History and compare rows 27 and 31. In January 2023 the counter sold zero cartridges and had stock throughout. Column F carries that zero into the fit. In May 2023 the counter sold six and ran out. Six is a lower bound on demand. F31 is blank and G31 gives that month zero exposure in the fit. Counting May’s six sales while charging the model for all 31 days would depress its estimate of summer demand.
There are 60 monthly records. Rows 7–54, May 2021 through April 2025, supply the four years used to learn the calendar. Rows 55–66 are reserved for testing forecasts one month at a time. Column C measures the length of each month in 30-day periods. A January selling ten units contributes ten sales in 31/30 periods. A February selling ten in 28 days ran at a higher daily rate.
Omitting stockouts is a practical compromise for a small workbook. If the counter sells out every summer, the few fully stocked months may all come from quiet years. When a part starts the month with six units, sells all six and gets no further receipts, a richer model can use the probability of demand at least six instead of discarding the month.
2. Updating October’s rate (SGD)
Open SGD (stochastic gradient descent). The fit assigns one rate to each month of the year. All twelve start at six cartridges per 30 days. Row 7 visits October 2022. Three calculations take place on that row.
- B7:E7 — the observation. B7 takes its date from
History!A24. October had 31 days and the counter sold five units. - F7:G7 — the forecast and its error. At the initial rate, October was expected to sell 6 × 31/30 = 6.20. Subtract the five sales. The gradient is +1.20, so October’s rate was too high.
- H7 and R7 — the adjustment. The step size is 0.032. Subtract 0.032 × 1.20 from October’s log rate. Column R holds October. The other eleven log rates carry over unchanged. In ordinary units, the change is 6 × exp(−0.0384) = 5.77 per 30 days. E5 and H5 show the before and after values.
Why adjust the logarithm? Exponentiating it gives a positive rate at which units can sell. If b is the log rate and e is the length of the month in 30-day periods, the expected count is μ = e × exp(b). Under a Poisson forecast, the derivative of the negative log likelihood with respect to b is simply μ minus the observed count. That is the subtraction in G7. For a fully stocked month with no sales it becomes μ. For the May stockout it is skipped.
Each pass visits all 48 training months once in a saved shuffle. The step size falls from pass to pass, so a late observation makes a smaller correction. Row 1542 holds the twelve log rates after 32 passes. Each row reads the preceding row, so Excel’s iterative-calculation setting can stay off. The workbook bounds each rate between 0.05 and 100 per 30 days. A part that regularly sells 150 a month would need a higher ceiling.
3. Checking May’s rate by hand (Calendar)
On Calendar, read May across row 11. The three fully stocked Mays sold 10, 13 and 12 cartridges. They contributed 93 days in all, or 3.10 periods. The Poisson rate that best fits those counts is 35 ÷ 3.10 = 11.29 units per 30 days. Column E calculates this directly. Column F arrives at 11.29 by taking the exponential of May’s last value on SGD. In December the difference is still visible after 32 passes. The fitted rate is 1.18 against an exact 0.97.
Column G divides each fitted rate by the average of the twelve in F20, 8.10. May’s index of 1.39 means a 30-day May runs about 39% above the underlying level. This separates the summer peak from growth in the business. A growing customer base can lift sales in every month while leaving this May multiplier unchanged.
For a single rate per month the division in column E would suffice. Gradient descent becomes more interesting for a merchant with hundreds of slow-selling parts. He can fit a summer pattern shared by a family of filters, while giving each filter its own level. A new part can then borrow four summers of evidence from the rest of the family. See learning seasonal indices with autodiff.
4. April’s forecast and April’s sales (Replay)
Open Replay. The calendar is now fixed. Each month starts with a level Lₜ, measured in units per 30 days before seasonality. Column B contains aₜ, the seasonal index multiplied by the length of that month in 30-day periods. Together they give the distribution of the month’s demand Yₜ:
After a fully observed month, divide the sales by aₜ to put them back on the scale of the level. Give that observation a weight α and carry the revised level into next month. This is the innovation state-space model (ISSM) used here:
Read April 2026 on row 18. Before the month began, the level in D18 was 9.26. Multiplying by April’s factor of about 0.987 gave an expected 9.14 sales in E18. The counter recorded 12 in C18. At the example gain of 0.35, I18 gives 65% weight to the old level and 35% to 12 ÷ 0.987. May opens at 10.27.
Try changing one sale count. In History!D66, enter 6 in place of 12. April’s forecast in Replay!E18 stays at 9.14. The level carried into May falls to 8.15, and the May forecast in Distribution!A4 falls from 14.80 to 11.74. Restore 12 before continuing. Shuffling the replay would let later sales influence earlier forecasts.
5. The chance of selling 40 by July (Forecast and Distribution)
Open Forecast. The upper chart groups total demand before July into five-unit bands. A bar above 35–39 includes every outcome from 35 through 39 cartridges. Both models expect 37.7, yet the updating model puts 6.6% on demand of 50 or more. Holding the level fixed gives only 3.1%. The last bar includes every count from 60 upward.
The lower chart shows where some of that extra spread comes from. If customers want eight cartridges in May, June’s mean falls to 19.19. If they want twenty, it rises to 25.67. Each set of bars gives a whole June forecast conditional on that May count. Follow Next: Distribution to see how Excel combines the months.
On Distribution, the small table at G13:J18 works through one split. Select Inspect the 20 + 20 split to see its formula in AE52. Column AE fixes May demand at 20. Row 52 fixes the two-month total at 40, which leaves 20 for June.
- May. AE8 gives a 3.90% chance of selling exactly 20 in May.
- June, given that May. AE9 contains the revised mean, 25.67.
POISSON(20,AE9,FALSE)gives the chance of exactly 20 in June at that rate. - Both together. The product in AE52 is 0.176%. Follow Return to the total in B52. B52 adds all 41 splits, from 0 + 40 through 40 + 0. The chance of exactly 40 sales is 4.8%.
For the order, read column D. The 43rd cartridge can sell in any summer with demand of 43 or more. D55 therefore includes all those totals, giving 25.4%. Only 3.8% of summers land on exactly 43 (B55). The sheet calculates D as one minus the probability of 42 or fewer. Even outcomes beyond the last displayed row count toward a sale.
Column F repeats the calculation with the May 1 level held fixed through June. The monthly counts are then independent, and their sum is Poisson with mean 37.7. The updating model has the same mean because, averaged over all possible Mays, the May surprise is zero. Its standard deviation rises from 6.1 to 7.6 units when a busy May can be followed by a busier June. Enumerating the splits is practical for two months. For a longer horizon one can sample entire paths, as in the M5 forecasting lecture, which uses negative-binomial counts.
6. Pricing the fourth case (Order)
On Order, row 13 prices the fourth case. Columns B and C show stock rising from 42 to 48. D13 adds the six chances in Distribution!D55:D60: 25.4% for the 43rd cartridge, 21.6% for the 44th, down to 10.2% for the 48th. The sum is 1.032 expected extra sales. The buyer pays freight once for the entire case, even if only one cartridge sells.
At $10 per sale those units earn $10.32 (E13). Deduct $9 freight and the fourth case earns $1.32 (F13). Case five earns only about $3 before freight, so the updating model stops at four. The fixed-level forecast expects 0.756 extra sales from case four, a $1.44 loss after freight (G13). It stops at three.
Try another freight quote. Enter 11 in Order!C6. F13 turns negative and both models recommend three cases (F17:G17). The chance of selling each cartridge is unchanged. Restore 9 for the original order. If the cartridges expire in July, the cost of leftovers must also enter the calculation.
How much evidence is there for the fourth case?
Return to Replay, columns G and H. Each scores the probability the forecast assigned to the count that came in. For an observed month, G7 computes the negative logarithm of that probability as =E7-C7*LN(E7)+GAMMALN(C7+1). An improbable outcome costs the model more. August’s stockout leaves both scores blank. Across the eleven scored months, row 20 gives average losses of 1.950 for the updating level and 2.077 for the fixed level. This benchmark keeps the original training level for the entire replay. The order comparison starts both models at the same, more recent May 1 level.
Eleven monthly counts make a short backtest for an order that depends on the upper end of two-month demand. The $1.32 is an expected gain under the model. Testing it would require two-month forecasts recorded before further orders, with the freight quotes available at the time. Choosing the gain that scores best on these eleven months would turn the test year into another year of training.
The Poisson assumption deserves scrutiny at the counter, too. If service firms buy four filters at a time, eight units may represent two jobs. Counting the eight as independent arrivals makes large orders look too rare. Keeping the quantity on each customer order would let the counter estimate how often those four-unit jobs occur. A single such job can account for most of an express case.