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 Receivable Analysis in SQL — 40 Worked Answers on a Real AR Ledger (DuckDB)

Accounts receivable analysis in SQL means the ageing, DSO, CEI and the disputed balances written as queries rather than as a worksheet of formulas. This notebook does all of it in DuckDB on a real receivables ledger: 70,300 rows across a CSV export, a Parquet file holding the newest quarter, and a nested JSON feed of bank remittances, with a subledger that does not agree with the general ledger and cash in the bank that no invoice claims. 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

AR Analysis in SQL — DuckDB Notebook
Format
Jupyter notebook (.ipynb), SQL throughout, outputs saved
Data
DATA DARE DD-ARC-002 · 70,300 ledger rows · 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 reach for SQL on a receivables ledger

Because the questions a collections meeting asks are the questions SQL was designed for: group this by customer, keep only what is open, rank it, compare it with last year. An ageing is a grouped sum with a date condition. DSO is one division. The overdue book is a filter. Written as queries they are short, they say what they mean, and anyone can read them back next month and see exactly how the number was reached — which is more than can be said for a worksheet of nested formulas pointing at cells.

And SQL is the one analytical language that does not belong to a single tool. The same query runs against a data warehouse, against your ERP's reporting database, and against the files on your own laptop. For a finance professional, the queries in this notebook are the transferable part.

DuckDB: SQL straight onto the files, with no import step

DuckDB is a database that runs inside your own session — no server, no account, no database file to look after. You install it with one line and point SQL at the files where they already are: `read_csv_auto` for the ledger export, `read_parquet` for the new quarter, `read_json` for the bank feed. Nothing is loaded or copied, and nothing is changed. It only reads the columns the query actually asks for, which is why this stays quick as the files grow.

That matters here because this dataset arrives the way finance data really arrives: eight files in four formats in one folder. The ledger is a CSV because that is what the ERP exports. The newest quarter is Parquet because it is a column store built for size. The dispute log is an Excel workbook because a person maintains it. The remittances are nested JSON because they came from a payment system over an interface. DuckDB reads three of those four by itself; the two Excel files come in through pandas in two lines, and the rest of the notebook cannot tell the difference.

Four views, one macro, and then the questions are easy

A view in SQL is a saved question, not a copy of the data. The notebook defines a handful of them — the two ledger files appended with their dates cast to a single type, the bank feed unnested into transfers and the invoice lines they settle, the ledger with its first-receipt date and due date attached, the amount owed at every month-end — and every later query reads off those. It is the same habit as building a measure once in Power BI and using it everywhere.

The keystone is a macro. A macro is a function you write in SQL, and one declared `AS TABLE` returns a table, so `ageing('2026-09-30')` can be used anywhere a table name can. Write the open-items logic once — raised by the date, not yet paid on it, bucketed by days past due — and ten questions become one line each, on any date you choose. That single idea is what turns forty questions into a file you can read in an afternoon.

The SQL worth stealing: window functions, QUALIFY, PIVOT

Three features do most of the heavy lifting, and all three replace work a spreadsheet does badly. A window function — `SUM(Amount) OVER (PARTITION BY EntityCode ORDER BY Month)` — turns the ledger into a running balance at every month-end in one line, in place of a column of formulas that breaks the first time a row is inserted. `QUALIFY` filters on the result of a window function the way `HAVING` filters on a `GROUP BY`, which is what lets the last two questions keep only the suspense transfers that match exactly one open invoice. And `PIVOT` turns the ageing buckets into columns, so the output reads like the ageing every finance team already knows.

SQL, Python or Excel?

All three, for different jobs, and the honest answer is that this ledger needs more than one. Excel is right for a one-off ageing on a few thousand rows and for the judgement at the end. SQL is right for the questions themselves — filtering, grouping, ranking and joining a book of 70,300 rows, where it is shorter and clearer than anything else. Python is right where the work leaves SQL behind: a chart, a file to send, a model to fit, a step that has to loop.

The same forty answers are published in pandas as well, in the AR Analysis in Python notebook, deliberately so you can read one against the other. Where the two differ is instructive: the ageing is a function in Python and a macro in SQL, the running balance is `cumsum` in one and a window function in the other, and the nested JSON is `json_normalize` against `UNNEST`. The findi360 AR Full-Scale Model course teaches this same set 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 JSON — plus the two Excel files, registered from pandas.
  3. First look — DESCRIBE for the column types and SUMMARIZE for a whole-table profile in one word.
  4. Fix the data — Append the new quarter, unnest the bank feed, and add five helper columns to the ledger.
  5. Six working views — Sales and targets, the amount owed each month-end, the ageing macro, transfers, disputes and unapplied cash.
  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 ageing 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 — which Excel cannot read — and find someone to convert it first.
  3. Rebuild the ageing buckets against the new reporting date and re-check every lookup.
  4. Repeat the dispute and unapplied-cash adjustments by hand, and reconcile to the control account again.
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 every figure is a query you can read back.

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

  • Finance professionals who want the SQL half of the toolkit, on a ledger rather than on a sample database
  • Collections and credit control teams whose ageing and DSO are rebuilt by hand every month
  • Anyone whose data arrives as CSV, Parquet or JSON across several files and will not fit a worksheet
  • Candidates preparing for the DATA DARE receivables 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 — the macro, the window function, QUALIFY — each 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. The first cell tells you if something is missing.

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.

Why is DuckDB reading CSV and Parquet but not the Excel files?

Because DuckDB reads CSV, Parquet and JSON natively and Excel it does not. The two Excel files are opened with pandas and handed to DuckDB with con.register, which makes a dataframe queryable as if it were a table. Two lines, and every query after that treats them like any other table.

Can I run these queries on my own receivables ledger?

Yes, once the column names match. The thinking is in the views and the macro, not in the questions: point the first block at your own export, keep the same column names or rename them once at the top, and the ageing, DSO, CEI and dispute analysis all follow.

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. If one had not matched, the file would not be here.

Keep going on findi360

Related models

  • AR Analysis in Python — Jupyter Notebook

    A complete receivables working file in pandas: load four file formats, append the new quarter, build six working tables, then answer forty graded questions — from the ageing bucket to the overdue book corrected for cash nobody could place.

  • Order to Cash Process Mining in SQL — DuckDB Notebook

    Process mining, done in SQL rather than in a specialist tool. An event log of 559,254 order-to-cash steps across 46,341 invoices: how long each handover really takes, how many invoices get through untouched by a person, how often collectors chase money that is already in the bank, who released a credit hold they had no authority to release, and how far a broken promise to pay actually slips.

  • Payables Reconciliation in SQL — DuckDB Notebook

    The payables side of a three-company group, answered in SQL: what is owed on either date basis, DPO, the overdue book, goods received not yet invoiced, the early-payment discounts that were missed, the invoices entered twice, the payments that went to an account nobody approved, and a year-end supplier statement reconciliation that leaves a balance nothing explains.

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.