Skip to main content
Data Resources

Models and stories for finance data

Working Excel, Python and SQL models built by finance professionals, and data stories that explain the numbers behind the news. Every model is explained sheet by sheet and paired with a DATA DARE practice dataset.

DuckDB model

Accounts Payable Reconciliation in SQL — 40 Worked Answers on a Real AP Ledger (DuckDB)

Accounts payable analysis is mostly reconciliation. What does the ledger say we owe, what does the supplier say, what arrived but has not been booked, and what has already been paid? This notebook answers all of it in SQL on a real payables ledger for three companies that share one supplier master — 49,790 lines in a CSV and a Parquet file, payment runs in nested JSON, and the GRNI log, the payment plan and the supplier statements in Excel. Every one of the forty answers was checked against the dataset's own answer book, on two versions of DuckDB, before the file was published.

By findi360 · Updated November 2026

Payables Reconciliation in SQL — DuckDB Notebook
Format
Jupyter notebook (.ipynb), SQL throughout, outputs saved
Data
DATA DARE DD-APY-002 · 49,790 ledger rows · three companies · CSV, Parquet, JSON and Excel
Covers
40 questions, easy to very hard
Needs
Python 3.9+, duckdb, pandas · checked on DuckDB 1.3.2 and 2.0.0

Download and share

Downloads need a findi360 account — create one in a minute and the file starts straight away. Already a member? Sign in

No account? Get this model by email.
One model by email is free. For more, a free account takes a minute.

Continue with Google

Why payables is a SQL problem before it is a spreadsheet problem

Because almost every payables question is a join. Is this invoice on the supplier's statement? Was it paid, and from which batch, and to which bank account? Is the same invoice in here twice? Did goods arrive in December that nobody has invoiced us for yet? Each one matches two sets of records against each other, which is the thing SQL was built to do and the thing a spreadsheet does with a wall of lookups that nobody can check.

And payables is where the money leaves. A duplicate invoice paid twice, a bank account quietly changed, a discount missed because the approval sat in someone's inbox — these are not reporting problems, they are cash. Written as queries they can be run every month in seconds, which is the difference between a control and a good intention.

Two dates, and why the answer changes

Every line in this ledger carries a document date — the date on the supplier's invoice — and a posting date, the day it reached the books. They are often days apart, and sometimes weeks. Ask what the group owed on 31 December on the posting basis and you get one number; ask on the document basis and you get a larger one, because invoices for December work were still arriving in January.

That gap is the year-end cut-off, and it is the single most common audit adjustment in payables. The notebook defines both bases as one-line macros and then asks the same question of each, which is how you size the problem rather than guess at it. The last question in the file puts the whole liability together: posted payables, plus the invoices dated before year end but posted after it, plus goods received and not yet invoiced at all.

The supplier statement reconciliation

A supplier statement is the supplier's own view of what you owe them, and it never quite agrees with yours. The useful work is not finding the difference — it is sorting it into piles that each have an explanation: invoices they have billed that you have not booked yet, payments you have made that they have not received yet, and whatever is left.

The notebook matches each statement line to the ledger invoice it names, on company, supplier code and the supplier's own invoice number, and then does exactly that sort. The residual — the pile with no explanation — is the one worth taking to a meeting, and in this group it is a credit the ledger cannot account for.

Three controls you could run on your own ledger tomorrow

First, duplicates. `ROW_NUMBER()` over company, supplier, invoice number and amount finds every second posting of the same invoice in one pass — and the notebook then asks how much of the current payables balance those duplicates make up, still unpaid.

Second, the bank account. Every approved account is in the supplier master; every account actually paid is in the payment file. Joining the two and keeping the rows where they differ is three lines of SQL and the most direct fraud check in payables.

Third, discounts. Where a supplier offers a discount for early payment, the notebook works out which payments missed the window and what that cost — a number most finance teams have never seen, because it never appears in any report.

SQL, Python or Excel?

Excel is right for the judgement at the end and for a one-off schedule. SQL is right for the matching, the grouping and the controls — it is shorter, it is checkable, and it runs again next month without being rebuilt. Python is right where the work leaves SQL behind: a chart, a file to send, a model to fit.

The same group's receivables ledger is published with its forty answers in both SQL and pandas, so the two languages can be read against each other on the same kind of problem. The findi360 courses teach these sets in Power BI and in Python side by side.

Inside the notebook

  1. Libraries — A cell that tells you which of the three libraries is missing before anything else runs.
  2. Point DuckDB at the files — Views over the CSV, the Parquet file and the nested JSON — plus the three Excel files, registered from pandas.
  3. First look — DESCRIBE, SUMMARIZE, and invoices against payments for each of the three companies.
  4. Fix the data — Append the new quarter, unnest the payment runs, and link every payment to the invoice it settles.
  5. Six working views — What is owed on either date basis, unpaid and overdue, the statements matched, the duplicates and the wrong bank accounts.
  6. The answers, Q01 to Q40 — One query per question, each printing its answer, and a final list of all forty.

Excel + DuckDB — the Power of Plus

Excel does this model well when all five of these are true. When two or more are not, you add DuckDB — not instead of Excel, beside it. That is the Power of Plus.

  1. One-off — you build it once, not again every month.
  2. Fixed structure — the same accounts, entities and layout each time.
  3. Small enough to check by eye — thousands of rows, not millions.
  4. One source — one ledger or one plan, not data scattered across systems and files.
  5. No live link needed — nobody expects it to update from the ledger by itself.
Excel

What next month's payables reconciliation really costs in Excel

  1. Export the ledger again and paste it in, hoping the columns arrived in the same order.
  2. Open the Parquet file and the nested JSON payment runs — which Excel cannot read — and find someone to convert them first.
  3. Rebuild the statement match with a wall of lookups, for every supplier, again.
  4. Re-run the duplicate check by eye, and take the bank-detail comparison on trust.
DuckDB

The same work, once it repeats

In DuckDB the files are never imported at all: point the same queries at next month's export, in whatever format it arrives, and the duplicate and bank-detail controls run themselves.

DuckDB still needs your judgement where the data is new — but everything after that repeats by itself.

Learn it on findi360: AR Full-Scale Model · Level 2

Notify me when it opens

Want to see what scattered data looks like? Three ERPs, three currencies and one consolidated group: DD-CON-004 — Diversified Group Close: Acquisition, Goodwill & Multi-ERP Consolidation

Who this model is for

  • Payables and procurement teams whose month-end reconciliation is rebuilt by hand
  • Financial controllers who need the year-end payables cut-off sized rather than estimated
  • Internal audit and finance teams looking for duplicate-payment and bank-detail controls they can actually run
  • Candidates preparing for the DATA DARE payables challenges and the Silver Seal test

Frequently asked questions

Do I need to know SQL already?

Only the shape of it. If you can read a SELECT with a WHERE and a GROUP BY you can follow the whole file: there is a short explanation in plain words before every block, and the harder features get a paragraph of their own where they first appear.

What do I have to install?

One line: pip install duckdb pandas openpyxl. There is no server, no account and no database file — DuckDB runs inside the notebook and reads the dataset files where they already are.

Which version of DuckDB does it need?

It was run and checked on DuckDB 1.3.2 and on DuckDB 2.0.0 and gives identical answers on both. One thing to know if you are on 2.0: fetchone() was removed from query results, so this notebook uses fetchall() throughout, which works on both.

Can I run these queries on my own payables ledger?

The reconciliation and the three controls transfer almost unchanged, once the column names match. The one thing to check first is your own sign convention: here invoices are positive and payments negative, so what is owed is a running total of one column.

Why does the answer change depending on which date I use?

Because a supplier invoice has a document date and a posting date, and at a month end they fall either side of the line. That is the cut-off, and three questions in the notebook measure it four different ways.

Are the answers in the file correct?

Every one of the forty was compared with the Expected_Result_Value in the dataset's own Question Bank, within its stated tolerance, on two versions of DuckDB — and then the notebook was executed from top to bottom and its printed answers checked again.

Keep going on findi360

Related models

  • AR Analysis in SQL — DuckDB Notebook

    The whole receivables question bank answered in SQL. DuckDB reads the CSV, the Parquet file and the nested JSON where they sit, four views and one macro carry the thinking, and forty queries of two or three lines each answer everything from the ageing bucket to the overdue book corrected for cash nobody could place.

  • Accounts Payable in Python — Jupyter Notebook

    The purchase ledger worked end to end: what is owed at any date, how much of it is overdue, how long suppliers really wait for their money, and the invoices that were posted twice and are still sitting in the balance.

  • General Ledger, Close and Controls in SQL — DuckDB Notebook

    A three-company group's whole general ledger, 1,172,802 journal lines, worked end to end in SQL: the statements built from raw debits and credits, the close tested on four different dates, the ledger reconciled to the exported trial balance and to the bank, and the control exceptions found — self-approvals, rubber-stamp approvals, after-hours entries, postings above someone's own approval limit and duplicate supplier invoices.

Need a model we have not built yet?

Tell us what you need. Members vote, and the most-requested models are built first — free to download.

Educational model on illustrative data. Not investment, accounting or tax advice. © findi360 — share freely with attribution.