Skip to content

Invoice Reconciliation

This example walks through reconciling an Excel export of orders against a CSV of line items — a common accounting workflow where IDs appear as substrings inside description fields.

You have two files:

orders.csv — order IDs from your system:

Invoice,Amount,Date
100154612,685.00,2025-01-15
100154874,1200.50,2025-01-16
100154312,450.00,2025-01-17

line_items.csv — line items from a vendor, where order IDs appear inside descriptions:

id,description,amount,status
1,"Payment for order #100154612 - Shipping",685.00,paid
2,"Overweight charge ref 100154874",45.00,pending
3,"Invoice 100154874 main charge",1155.50,paid
4,"Credit memo 100154312",450.00,paid
5,"Service fee Q1 2025",75.00,paid

The challenge: order 100154874 appears in two line items (rows 2 and 3), and the IDs are buried inside free-text descriptions.

Terminal window
vgrid diff orders.csv line_items.csv \
--key Invoice \
--match contains \
--contains-column description \
--key-transform digits \
--on-ambiguous report \
--save-ambiguous ambiguous.csv \
--no-fail \
--out json

What each flag does:

FlagPurpose
--key InvoiceLeft key column: the order ID
--match containsSubstring matching mode
--contains-column descriptionSearch the right description column (not the right id column)
--key-transform digitsExtract only digits — "Payment for order #100154612" becomes 100154612
--on-ambiguous reportInclude ambiguous matches in output instead of failing
--save-ambiguous ambiguous.csvExport ambiguous matches for manual review
--no-failExit 0 regardless of diffs (agent-friendly)

Order 100154874 matches two line items. The ambiguous export shows:

left_key,candidate_count,candidate_keys
100154874,2,Overweight charge ref 100154874|Invoice 100154874 main charge

This tells you: one order split across two line items (an overweight surcharge + main charge). The amounts should sum to the order total: 45.00 + 1155.50 = 1200.50.

Pipe the ambiguous items into calc to check the sum:

Terminal window
vgrid convert line_items.csv -t csv --headers \
--where 'description~"100154874"' \
--select amount | \
vgrid calc '=SUM(A:A)' -f csv

Output: 1200.5 — matches the order amount.

Step 4: CSV output for downstream processing

Section titled “Step 4: CSV output for downstream processing”

For a full reconciliation report:

Terminal window
vgrid diff orders.csv line_items.csv \
--key Invoice \
--match contains \
--contains-column description \
--key-transform digits \
--on-ambiguous report \
--no-fail \
--out csv \
--output recon-report.csv
Data shapeTransformExample
Clean numeric IDsdigitsOrder #100154612100154612
Mixed alphanumeric codesalnumINV-2025-X42INV2025X42
Already cleantrim (default)" 100154612 "100154612
  • Don’t use --key-transform digits if IDs contain meaningful letters. Use alnum instead.
  • Ambiguous matches are expected in contains mode. Don’t treat them as errors — they often represent split transactions or multiple line items per order.
  • Always use --no-fail in automated workflows. Parse the JSON summary to determine results.