DEV Community

Alan Matthew
Alan Matthew

Posted on

Accounts Receivable Turnover in Code: The Formula, the Gotchas, and a Free Calculator

If you're building anything that invoices customers, you eventually get asked: "How fast are we actually getting paid?"

The standard answer is accounts receivable (AR) turnover. It's a short formula, but a few input choices change the result, and they're easy to get wrong in code.

The formula

AR Turnover = Net Credit Sales / Average Accounts Receivable

Average AR  = (Beginning AR + Ending AR) / 2
Enter fullscreen mode Exit fullscreen mode

It tells you how many times in a period a business collects its average receivables balance. Higher means customers pay faster. Lower means cash is sitting in unpaid invoices.

A closely related metric is days sales outstanding (DSO), the average number of days it takes to collect:

DSO = Days in Period / AR Turnover
Enter fullscreen mode Exit fullscreen mode

A worked example

A business reports, for the year:

  • Net credit sales: $600,000
  • Beginning AR: $50,000
  • Ending AR: $70,000
  1. Average AR = (50,000 + 70,000) / 2 = $60,000
  2. AR turnover = 600,000 / 60,000 = 10.0
  3. DSO = 365 / 10 = 36.5 days

So the company collects its receivables about 10 times a year, and a typical invoice takes around 36 days to get paid.

Implementing it in JavaScript

Two things to get right: money should be handled in integer cents, and the denominator can be zero.

const toCents = (n) => Math.round(n * 100);

function arTurnover({
  netCreditSales,
  beginningAR,
  endingAR,
  daysInPeriod = 365,
}) {
  const sales = toCents(netCreditSales);
  const avgAR = (toCents(beginningAR) + toCents(endingAR)) / 2;

  if (avgAR <= 0) {
    throw new Error("Average accounts receivable must be greater than zero");
  }

  const turnover = sales / avgAR;
  const dso = daysInPeriod / turnover;

  return {
    averageAR: avgAR / 100,
    turnover: Number(turnover.toFixed(2)),
    dso: Number(dso.toFixed(1)),
  };
}

console.log(
  arTurnover({ netCreditSales: 600000, beginningAR: 50000, endingAR: 70000 })
);
// { averageAR: 60000, turnover: 10, dso: 36.5 }
Enter fullscreen mode Exit fullscreen mode

Gotchas worth handling

  • Use credit sales, not total sales. Cash sales never create a receivable, so including them inflates the ratio. If you only have total sales, the result is an approximation, and your UI should say so.
  • Match the period to daysInPeriod. A quarterly calculation should use 90 or 91 days, not 365, or DSO will be wrong by a factor of four.
  • Average, don't just use the ending balance. Seasonal businesses can have a very different year-end AR, which distorts the ratio.
  • Guard against zero. A new business with no receivables will divide by zero. Return a clear error or "not applicable" instead of Infinity.
  • Compare within an industry. A "good" turnover varies a lot between sectors, so a single number only means something against a benchmark or your own trend.

Just need the number?

If you'd rather not write and maintain this yourself, here's a free calculator:

Accounts Receivable Turnover Calculator - Free AR Ratio Calculator | TakeMyAccountingClassForMe.com

Free AR turnover calculator with days sales outstanding. Perfect for accounting students and financial analysis.

favicon takemyaccountingclassforme.com

Direct link in case the embed doesn't render: Accounts Receivable Turnover Calculator

Takeaways

  • AR turnover is net credit sales divided by average receivables, and DSO is days in the period divided by turnover.
  • Most bugs come from the inputs: total vs. credit sales, mismatched periods, and zero denominators.
  • Treat the result as a trend to watch, not an absolute grade.

If you've built receivables reporting into an invoicing or finance tool, I'd like to hear how you handled edge cases like partial payments or credit notes.

Top comments (0)