· Updated  · margin

The Margin Formula: Why Unknown Cost Shows Nothing

The exact formula, why every value is an integer number of cents, and why a fill with no acquisition cost on file shows no margin rather than a confident zero.

If you are going to act on a number, you are entitled to know how it was made. Here is the whole calculation.

The formula

For a single fill:

revenue = payer paid + patient pay - known post-adjudication fees
margin  = revenue - acquisition cost for the dispensed quantity

Three things in that need spelling out.

Patient pay is revenue. The copay is money the pharmacy receives. Excluding it would understate margin on every fill with cost sharing, which is most of them.

Fees are subtracted, not netted somewhere else. Any post-adjudication amount the platform knows about is money the pharmacy does not keep, so it comes out of revenue before the comparison to cost. Fees that surface later, on the remittance, are reconciliation work. That belongs to Attergo Billing, reading the same event stream, so the two products share one data model instead of two competing versions of your revenue.

Cost is for the quantity dispensed, not for the package you bought.

Everything is an integer number of cents

No floating point value enters or leaves the calculation. Money is held as an integer count of minor units from ingestion to display.

Margin subtracts two nearly equal numbers, which is precisely where binary floating point is proportionally worst. The familiar demonstration is that 8.115 multiplied by 100 and rounded comes out as 811 in most languages rather than 812, because the stored value was never exactly 8.115. An error of one cent is meaningless on a single line and considerable across a month of fills, particularly when the whole claim is that we can tell you a fill lost $2.14.

A build check enforces the rule. A money column typed as a float, or a money value parsed through a float, fails the build.

Scaling a package price to a fill

Wholesaler invoices price a package. A fill dispenses a quantity.

cost for this fill = round(package cost x dispensed quantity / package quantity)

Rounding happens once, at the end. Scaling with a decimal and rounding on every line accumulates error in one direction across a month. A package quantity of zero or less returns no cost rather than an error or an infinity, because a bad reference file should degrade to “we do not know” and never to a number.

The cost basis ladder

A margin is only as trustworthy as the cost it was computed against, and cost quality varies enormously. Every result carries the basis it used and a confidence level, and both appear on screen next to the number.

BasisWhat it isConfidence shown
InvoiceYour own wholesaler invoice for that exact NDCHigh
OverrideA named person entered it, and it is attributableHigh
Invoice, similarYour invoice for a different package size of the same drug, scaledMedium
NADACThe CMS national benchmarkLow
UnknownWe have nothingNone, and no margin is computed

A NADAC-based margin is labelled as indicative, in those words, on the fill. NADAC is easy to mistake for your cost. It is a survey of retail community pharmacy invoice prices that excludes mail order and specialty pharmacies, it does not include rebates or off-invoice discounts received after the invoice is paid, and since the December 2024 updates CMS has calculated monthly generic rates using a three-month moving average to damp volatility caused by fluctuating survey participation. A reasonable benchmark, a poor substitute for your invoice, and a system that quietly uses one as the other is producing confident fiction.

A margin scaled from a different package size is also labelled, with the reason, because it is arithmetic on a fact rather than the fact itself.

Why an unknown cost produces no margin rather than zero

If we have no acquisition cost for an NDC, the arithmetically convenient move is to treat the cost as zero. Margin then equals revenue, the fill reports as pure profit, the dashboard is complete, and every number has a value in it.

It is also the most dangerous answer available. A missing cost is not evidence of a free drug. Treating it as zero means the fills we know least about are exactly the fills that look best, and the error runs toward hiding losses rather than raising false alarms. A pharmacy reading that report would conclude its worst-documented products were its most profitable ones.

The calculation returns no margin. Specifically:

  • Revenue is still reported, because we do know what came in.
  • Cost, margin and margin percentage are all null. Not zero, not estimated.
  • The fill is not marked underwater, because we genuinely do not know whether it is.
  • The fill is flagged for attention with a reason of “no cost”, so it appears in a work queue rather than disappearing from the report.
  • The note shown on screen says that no acquisition cost is on file for this NDC and that importing a wholesaler invoice will produce a margin.

Expect a meaningful number of fills showing no margin in week one of a pilot. That is the truth about your cost data, and the fix is invoice coverage rather than a better guess.

Percentage is of revenue, not of cost

Margin percentage is margin divided by revenue, to one decimal place. “We made twelve percent on that fill” is universally understood as margin over what came in, and expressing it over cost would produce a different number that nobody means.

When revenue is zero, the percentage is null rather than an error or an infinity. That case is real: a reversal, or a claim that paid nothing. Where revenue is zero and cost is known, the note says the fill was reimbursed nothing and the full acquisition cost is a loss.

Two thresholds, either of which can flag

A fill is flagged when it loses money, and also when it makes too little to be worth doing. Both tests apply.

The absolute test catches a real loss. The percentage test catches the thin one. The default percentage floor is five percent. Neither test works alone: five percent on a $900 specialty fill is $45 and perfectly acceptable, while five percent on a $4 generic is twenty cents and not worth the label. Thresholds are per tenant, so a pharmacy with a different view can set its own.

The boundaries of the number

  • Point-in-time. The fill-level margin states what was known at adjudication. Comparing the promise against what a remittance actually paid is reconciliation, and it belongs to Attergo Billing on the same event stream, outside this number, where it would otherwise blur what the counter decision was based on.
  • Fill economics, not contract economics. Whether you are meeting a generic effective rate guarantee across a book of business is a different calculation on a different time horizon, and Attergo Intelligence reports it at that horizon.
  • Computed from what the events carry. A fee no system transmitted is not in the number, which is why the basis and note travel with every figure.

The wider platform is eight products on one event spine: Margin, Billing, Audit, Authorizations, Inventory, Compliance, Intelligence, and Integrations, which is the spine. Each number stays inside its honest boundary, and the products compose because the boundaries are exact.

How to check our arithmetic

Do not take any of the above on trust. In a pilot, this exercise settles it.

  1. Pick ten fills across a range: a cheap generic, a brand, one with a large copay, a reversal, and something with no invoice on file.
  2. For each, write down what you believe the pharmacy received and what you believe the drug cost, from your own records.
  3. Compare against the fill detail, which shows revenue, cost, the basis, the confidence and any note.
  4. Where the numbers differ, the cause is almost always one of three things: a fee we did not know about, a cost basis that is NADAC rather than your invoice, or a package-size mismatch on the invoice match.

All three are visible on the screen. A disagreement you can trace in four minutes is a product working correctly. A number you cannot take apart is not worth having, whoever produced it.

See it on your own fills. Attergo Margin is where this runs, and a demo will put your ten fills on the screen.

Run this on your own claims.

Attergo prices every fill against the contract that governs it and shows you the gap before the fill leaves the counter.