How to calculate Days Sales Outstanding (DSO)

Days sales outstanding is the average number of days it takes to collect payment after a sale.

Formula

DSO = (accounts receivable ÷ credit sales) × days in period

SQL query

This example assumes: invoices(id, customer_id, issued_at, amount, paid_at). It is written in PostgreSQL syntax; date functions differ slightly in MySQL, BigQuery and SQLite, and your column names will differ from these.

WITH ar AS (
  SELECT SUM(amount) AS receivable
  FROM invoices
  WHERE issued_at <= DATE '2026-09-30'
    AND (paid_at IS NULL OR paid_at > DATE '2026-09-30')
), sales AS (
  SELECT SUM(amount) AS credit_sales
  FROM invoices
  WHERE issued_at >= DATE '2026-07-01' AND issued_at <= DATE '2026-09-30'
)
SELECT ar.receivable / NULLIF(sales.credit_sales, 0) * 92 AS dso_days
FROM ar, sales;

Common mistakes that make Days Sales Outstanding (DSO) wrong

  • Use credit sales, not cash sales, in the denominator.
  • Seasonal sales swings distort DSO; compare the same quarter year on year.
  • A few very late payers drive the average; also list invoices by age.

Ask for Days Sales Outstanding (DSO) 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.

  • What is our DSO for the last quarter?
  • Which customers have the oldest unpaid invoices?

Frequently asked questions

What is Days Sales Outstanding (DSO)?
Days sales outstanding is the average number of days it takes to collect payment after a sale.
How do you calculate Days Sales Outstanding (DSO)?
DSO = (accounts receivable ÷ credit sales) × days in period. The SQL example on this page shows the same calculation against a simple table.
What commonly goes wrong when calculating Days Sales Outstanding (DSO)?
Use credit sales, not cash sales, in the denominator.