{"slug": "why-llm-3-way-invoice-matching-double-counts-short-deliveries-and-the-excel-that", "title": "Why LLM 3-Way Invoice Matching Double-Counts Short Deliveries (And the Excel Formula That Fixes It)", "summary": "A developer built a deterministic 3-way invoice matching method that fixes two common LLM arithmetic failures: price variance computed on invoiced quantity instead of received quantity, which double-counts short deliveries, and parsers treating unsigned vendor packing slips as accepted inventory. On a synthetic case (PO-7416, GRN 9906, Invoice BX-118, $1,224.00 billed), the corrected split reconciles to $0.00 across supported, short-delivery, price-variance and freight-cap buckets. The developer published a four-sheet Excel workbook with a Buyer-Signed? SUMIFS gate and a generator script on GitHub.", "body_md": "When you drop a purchase order, a receiving log, and a supplier invoice into a general-purpose LLM and ask \"how much should we hold back?\", the output usually looks reasonable until you add the columns up.\n\nIn our testing on a synthetic 3-way match case (`PO-7416`, `GRN 9906`, `Invoice BX-118`, total billed `$1,224.00`), the most common failure was not OCR. It was arithmetic. Specifically, two bugs showed up over and over again when a single invoice combined a short delivery, a unit price increase, and excess freight.\n\nSuppose a line item has:\n\n`Q_p` at PO unit price `P_p`\n`Q_r`\n`Q_i` at invoiced unit price `P_i`\nWhen `Q_i > Q_r` (short delivery) and `P_i > P_p` (price increase) happen on the same line, a naive calculation does this:\n\n```\nShort Delivery = (Q_i - Q_r) * P_i\nPrice Variance = Q_i * (P_i - P_p)   <-- wrong: uses Q_i instead of Q_r\n```\n\nIf you sum `Supported + Short Delivery + Price Variance`, you overshoot the invoice total by `(Q_i - Q_r) * (P_i - P_p)`. You charged the supplier for a price increase on units you already excluded for not being delivered.\n\nThe clean algebraic split that reconciles to `$0.00` is:\n\n```\nSupported Amount   = Q_r * P_p\nShort Delivery     = (Q_i - Q_r) * P_i\nPrice Variance     = Q_r * (P_i - P_p)\n```\n\nCheck the sum:\n\n```\nQ_r * P_p + (Q_i - Q_r) * P_i + Q_r * (P_i - P_p) = Q_i * P_i\n```\n\nEvery dollar of the billed line lands in exactly one bucket.\n\nThe second failure happens before the math even starts. Suppliers often attach their own packing slip or shipping confirmation to an invoice PDF. If a parser reads every quantity document indiscriminately, it treats an unsigned vendor slip as accepted inventory.\n\nIn a spreadsheet, you can block this structurally by adding a `Buyer-Signed?` column (`Yes` / `No`) to the receiving log and wiring it directly into `SUMIFS`:\n\n```\n=SUMIFS('Receiving Log'!$E$2:$E$100, 'Receiving Log'!$B$2:$B$100, A2, 'Receiving Log'!$G$2:$G$100, \"Yes\")\n```\n\nAny row marked `No` contributes `0` to accepted received quantity, so unverified packing slips never silently clear a short-delivery hold.\n\nFreight lines rarely have a quantity variance, so they get skipped in basic SKU-matching scripts. A simple line-level cap check catches it:\n\n```\n=MAX(0, Billed_Freight - PO_Freight_Cap)\n```\n\nRunning all three checks on the synthetic `PO-7416 / GRN 9906 / Invoice BX-118` pack splits the `$1,224.00` invoice cleanly with a `$0.00` reconciliation check (`=ROUND(Invoice_Total - Supported - Disputed, 2)`):\n\n| Bucket | Amount | Rule | \n|---|---|---|\n| Supported by current records | `$914.00` | `Q_r * P_p` + freight within PO cap | \n| Short delivery (unreceived / unsigned) | `$216.00` | `(Q_i - Q_r) * P_i` | \n| Price increase on received units only | `$64.00` | `Q_r * (P_i - P_p)` | \n| Freight above written cap | `$30.00` | `MAX(0, Billed - Cap)` | \n| **Invoice Total** | **`$1,224.00`** | **Variance check: `$0.00`** | \n\nI put the 4-sheet workbook (`PO`, `Receiving Log`, `Vendor Invoice`, and `3-Way Variance Audit`, with formulas and the `Buyer-Signed?` `SUMIFS` gate) plus its generator script on GitHub so you can inspect the formulas or adapt them for your own AP reviews:\n\nIf you need to pull the line items and page-level quotes out of scanned PDFs before running the math, I also built a small web tool around this exact deterministic audit split: [https://apdispute.com/invoice-dispute-evidence-audit](https://apdispute.com/invoice-dispute-evidence-audit) (uses the same synthetic case as a no-login sample).\n\nIf your team handles partial shipments with prior invoices already paid against the same PO, I would be curious how you track cumulative prior billing in Excel without turning the sheet into a maintenance headache.", "url": "https://wpnews.pro/news/why-llm-3-way-invoice-matching-double-counts-short-deliveries-and-the-excel-that", "canonical_source": "https://dev.to/rickzhang/why-llm-3-way-invoice-matching-double-counts-short-deliveries-and-the-excel-formula-that-fixes-it-moc", "published_at": "2026-11-29 05:35:12+00:00", "updated_at": "2026-11-29 05:42:53.201269+00:00", "lang": "en", "topics": ["ai-tools", "large-language-models"], "entities": ["GitHub", "apdispute.com"], "also_reported_by": [], "takeaway": "Compute price variance on received quantity (Q_r * (P_i - P_p)), not invoiced quantity, or the invoice overshoots by (Q_i - Q_r) * (P_i - P_p); gate received quantities on a Buyer-Signed? flag so unsigned packing slips contribute zero.", "recommendation": {"advice": "When an LLM splits invoice variances, recompute each bucket algebraically and check the sum reconciles to the invoice total, and filter receiving rows to buyer-signed entries before matching.", "playbook": "output-verification", "playbook_url": "https://wpnews.pro/playbooks/output-verification"}, "alternates": {"html": "https://wpnews.pro/news/why-llm-3-way-invoice-matching-double-counts-short-deliveries-and-the-excel-that", "markdown": "https://wpnews.pro/news/why-llm-3-way-invoice-matching-double-counts-short-deliveries-and-the-excel-that.md", "text": "https://wpnews.pro/news/why-llm-3-way-invoice-matching-double-counts-short-deliveries-and-the-excel-that.txt", "jsonld": "https://wpnews.pro/news/why-llm-3-way-invoice-matching-double-counts-short-deliveries-and-the-excel-that.jsonld"}}