AI disclosure: I used AI tools to help draft this article. I ran the formulas and the snippet below before publishing.
Three-way matching sounds like an accounting chore until the first duplicate invoice goes through. The rule is simple: an invoice is only payable if it matches a purchase order (what you agreed to buy) and a delivery note (what actually arrived). The hard part is that the three lists never line up by row, and eyeballing them does not scale past a hundred lines.
Here is the version I use, built so that every mismatch is explainable rather than just flagged.
Start with one key, not three
The first mistake is matching on whatever is convenient: supplier name here, description there. Pick one key that appears in all three documents, usually the PO number plus the line number. If the delivery note does not carry it, that is a process problem worth fixing before any spreadsheet work, because every later reconciliation inherits the ambiguity.
With the key in place, the three lists become three tables with a shared column, and the matching is a join.
Three checks, in this order
1. Quantity: invoiced against delivered. For each key, sum the delivered quantity and the invoiced quantity. A difference means either a short delivery or an over-billing. Do not net them across keys; a short line on one item does not excuse an extra line on another.
2. Price: invoiced against ordered. Compare the unit price on the invoice to the price on the PO. A price change after the order is legitimate only if there is a documented amendment, so the output of this check should be a list to review, not an automatic pass or fail.
3. Duplicates: the same invoice twice. Group by supplier and invoice number, and also by supplier, date and amount. The second grouping catches the case where the same bill arrives with two different invoice numbers, which is exactly what a resubmitted or re-keyed invoice looks like.
import pandas as pd po = pd.read_excel("po.xlsx") # key, qty_ordered, unit_price dn = pd.read_excel("delivery.xlsx") # key, qty_delivered inv = pd.read_excel("invoices.xlsx") # key, invoice_no, qty_invoiced, unit_price, amount, date qty = (dn.groupby("key")["qty_delivered"].sum() .to_frame() .join(inv.groupby("key")["qty_invoiced"].sum(), how="outer") .fillna(0)) qty["qty_diff"] = qty["qty_invoiced"] - qty["qty_delivered"] print("quantity mismatches:\n", qty[qty["qty_diff"] != 0]) price = inv.merge(po[["key", "unit_price"]], on="key", suffixes=("_inv", "_po")) price["price_diff"] = price["unit_price_inv"] - price["unit_price_po"] print("price mismatches:\n", price[price["price_diff"].abs() > 0.001]) dupes = inv[inv.duplicated(subset=["supplier", "invoice_no"], keep=False)] same_amount = inv[inv.duplicated(subset=["supplier", "date", "amount"], keep=False)] print("duplicate invoice numbers:\n", dupes) print("same supplier/date/amount:\n", same_amount) Run the quantity check first. If it fails, the price check will produce noise on the same lines and you will spend the afternoon on the wrong problem.
Make every exception explainable
A mismatch list is only useful if each line says why it is on the list. Three columns do most of that work: the expected value, the actual value, and the difference. Anyone reviewing it, including you in six months, can then decide without re-opening the source documents.
Keep the three source files untouched and write the result to a new workbook with one sheet per check plus a summary sheet that counts exceptions by supplier. The count per supplier is the number that actually changes behaviour: one supplier with exceptions every month is a supplier conversation, not a spreadsheet problem.
The part that is not a spreadsheet
The matching is easy once the data is clean. What breaks in practice is that the three documents come from three systems, in three layouts, with three date formats. Most of the work is normalising them, and that work repeats every month, so it is worth doing once in code rather than every month by hand.
If you would rather not build it, I make a small Windows app for this, ThreeWayMatch, which does the three checks against files you load. Either way, run the checks in the order above: quantity, then price, then duplicates.
I'm Murabyte. I build small tools for spreadsheet and document work. AI tools helped draft this post; the formulas and snippet were run before publishing.
