How to calculate Days of Inventory (DIO)
Days of inventory is the average number of days stock sits before it is sold.
Formula
Days of inventory = (average inventory ÷ cost of goods sold) × days in periodSQL query
This example assumes: inventory_snapshots(as_of, value), sales(sold_at, cogs). It is written in PostgreSQL syntax; date functions differ slightly in MySQL, BigQuery and SQLite, and your column names will differ from these.
WITH avg_inv AS (
SELECT AVG(value) AS avg_value FROM inventory_snapshots
WHERE as_of >= DATE '2026-07-01' AND as_of <= DATE '2026-09-30'
), c AS (
SELECT SUM(cogs) AS cogs FROM sales
WHERE sold_at >= DATE '2026-07-01' AND sold_at <= DATE '2026-09-30'
)
SELECT avg_inv.avg_value / NULLIF(c.cogs, 0) * 92 AS days_of_inventory
FROM avg_inv, c;Common mistakes that make Days of Inventory (DIO) wrong
- It is the inverse of turnover scaled to days; do not report both as separate insights.
- Obsolete stock inflates the average without being sellable.
- Use the same period length (92 days here) as the quarter measured.
Ask for Days of Inventory (DIO) in plain English
Instead of writing the query yourself, you can type the question. SchemaChat turns it into SQL against your connected database or uploaded file, runs it, and shows the SQL and the figures it used so you can check the answer before you share it. It does not replace your judgement about the definition: check that the query matches the formula your business uses.
- How many days of inventory do we hold by category?
- How has days of inventory trended over the last year?