All work

IFan invoice has no matching paymentTHENflag it and rank it by money at risk.

Automated billing reconciliation and anomaly detection. A rule-based reconciliation engine for high-volume logistics billing. It matches about 99,000 invoices and payments, flags the billing anomalies that quietly erode margin, and ranks every exception by € at risk. Includes an exploratory machine-learning extension for anomaly detection.

99K+transactions reconciled (50,250 invoices, 48,779 payments)
99.7%payment match rate
€214krevenue at risk surfaced
2,767exceptions ranked by impact

My role. Developed with an AI-assisted workflow: I defined the business logic, reconciliation rules and validation criteria, and used AI tools to write the Python implementation.

The data. A synthetic dataset modelled on billing and logistics operations, with no proprietary information. Fully reproducible from a fixed seed: code on GitHub.

Reconciliation is manual, slow, and leaks margin

A logistics operation issues tens of thousands of invoices a month. Matching them to incoming payments is a spreadsheet-driven process, so billing errors slip through: duplicate invoices, wrong rates, misapplied fuel surcharges, short payments, unapplied cash. Each erodes margin or inflates days sales outstanding, and at volume nobody can review them all by hand.

What I built

An end-to-end, one-command pipeline

A synthetic but realistic dataset (500 customers, 12 months, about 3% of transactions seeded with six real-world error types as hidden ground truth), a SQL reconciliation core, an Isolation Forest anomaly layer, and an evaluation of both against that ground truth.

The six anomaly types

Injected at about 3%, held out as ground truth

Rate discrepancy, duplicate invoice, fuel-surcharge error, short or over payment, unapplied cash, overdue. Plus deliberately dirty data (mixed date formats, noisy customer keys, swapped currency labels) so the cleaning stage is genuine.

Most of the logic lives in SQL; machine learning closes the gap

Cleaning, exact and fuzzy invoice-to-payment matching, duplicate detection via window functions, and rate-card revalidation are all expressed in SQL. Python handles data generation, the anomaly model and evaluation.

  1. GeneratePython and Faker, seeded. Rate cards, terms, dirty data, hidden labels.
  2. CleanNormalise keys, fix currency labels, parse mixed date formats.
  3. MatchExact on reference, then fuzzy by customer and amount (window rank).
  4. RulesDuplicates, rate revalidation, short or over pay, unapplied cash.
  5. ModelExploratory: an Isolation Forest scores each invoice for subtle anomalies.
  6. RankExceptions register with aging, severity and € at risk, fed to Power BI.

Data model

Four reference and transaction tables, plus a hidden ground-truth table.

customers customer_id · segment terms · rate_card_id rate_card service · zone · rate/kg invoices invoice_id · customer_id total_amount · date fuel_index month · surcharge_pct payments payment_id invoice_id · amount rate_card service zone · rate/kg fuel_index month surcharge_pct customers customer_id segment terms rate_card_id invoices invoice_id customer_id total_amount date payments payment_id invoice_id amount

Rules are precise; machine learning recovers what rules cannot see

Because every anomaly was seeded, detection could be measured exactly. Three systems compared against the same ground truth.

Detection performance

SystemPrecisionRecallF1
Rules only99.4%83.3%0.91
Machine learning only18.8%19.0%0.19
Rules and machine learning53.2%93.8%0.68

Combining them lifts recall from 83% to 94%. Precision falls because the model adds candidates a reviewer triages in € order: a fuller net, not a cleaner one.

Recall by anomaly type

Where each layer earns its keep.

RulesMachine learning

Five of the six anomaly types are shown. Overdue invoices occur naturally rather than being seeded, so there is no ground truth to measure recall against; the aging rule flags them in the exceptions register.

The insight. The rule engine hits 99% precision but is structurally blind to one whole error class: subtle fuel-surcharge mistakes sit under its fixed 2% threshold, giving 0% recall. The Isolation Forest, learning the normal shape of an invoice, recovers 63% of them. Machine learning here complements business rules, it does not replace them. Rules give explainability and precision on known patterns; the model extends coverage to the unknown ones.

Reconciliation Control Tower

The pipeline feeds a two-page Power BI report. Executives see exposure and trend; operations drill into a ranked, filterable exception queue with a model-performance panel. The numbers shown are the live pipeline output.

Control Tower — Executive page: KPI cards, € at risk by anomaly type, monthly match-rate trend, and top 10 customers by € at risk
Page 1, Executive. Exposure at a glance: match rate, € at risk, open exceptions and detection recall, with € at risk by anomaly type, the match-rate trend, and the top accounts driving exposure.
Control Tower — Operational page: slicers, exceptions register ranked by € at risk, anomaly type by detection method matrix, and a model-performance panel
Page 2, Operational. The review queue: a filterable exceptions register ranked by € at risk, the matrix of anomaly type by detection method, and a model-performance panel comparing rules, machine learning and the combined system.

Tooling and reproducibility

SQL

Cleaning, exact and fuzzy matching, window-function duplicate detection, rate-card revalidation, exceptions register.

Python

pandas and Faker generator with a fixed seed; date parsing; orchestration in one script.

scikit-learn (exploratory)

Isolation Forest on per-invoice features: rate deviation, surcharge ratio, payment behaviour, peer z-scores.

Power BI

Two-page Control Tower over the exported exceptions, trend and KPI feeds.

One command, fully reproducible. A single run_pipeline.py regenerates the data, runs the SQL layer, scores the model, evaluates against ground truth, and exports the dashboard feeds, deterministically, in about 16 seconds.

Related case study. The same decision-logic mindset applied on the job: an internal application that automated billing-credit approvals, cutting turnaround from about 2 business days to 2–3 minutes. Read the auto-approval case study.