Order to Cash Process Mining in SQL — 50 Worked Answers on a 559,000-Event Log (DuckDB)
Most finance analysis asks what the numbers are. Process mining asks how they got there. This dataset is not a ledger — it is a log of every step in the order-to-cash cycle, with a timestamp and a user on each one: the order arriving, the credit check, the hold and its release, the dispatch, the delivery, the invoice posted, sent and viewed, the reminder, the dunning notices, the collector's call, the promise to pay, the payment and the cash finally being applied. Fifty questions turn that into findings a finance director can act on, and all fifty are answered here in SQL. Every answer was checked against the dataset's own answer book, on two versions of DuckDB, before the file was published.
By findi360 · Updated November 2026
- Format
- Jupyter notebook (.ipynb), SQL throughout, outputs saved
- Data
- DATA DARE DD-ARC-003 · 559,254 events · 46,341 invoices · CSV, Parquet, JSON and Excel
- Covers
- 50 questions, easy to very hard
- Needs
- Python 3.9+, duckdb, pandas · checked on DuckDB 1.3.2 and 2.0.0
What process mining actually is
An event log records what happened, when, and who did it. Given one, you can measure the process rather than describe it: where the days go between delivering goods and billing for them, which invoices skip a step entirely, how long an exception sits before somebody clears it, and which handovers are quick on average but occasionally terrible. None of that is visible in a ledger, because a ledger only keeps the final state.
It is usually sold as a specialist discipline with specialist software. It does not have to be. An event log is a table, the questions are grouped aggregates over it, and SQL answers them well — which is the point this notebook is making.
The one idea worth taking away
An event log is tall: one row per thing that happened. Almost every question is about the gap between two steps. Asked against a tall log, each of those needs its own self-join, and the queries get ugly fast.
So turn it once into one row per invoice with a column per milestone — order received, delivered, invoice posted, invoice sent, invoice viewed, payment received, cash applied. In SQL that is a single `GROUP BY` with an aggregate filter per column, one pass over the log, and afterwards every cycle time is a subtraction and twenty-odd questions become one line each. That view is section 6.1, and it is the thing to copy into your own work.
What the log finds in this group
Three findings stand out, and all three are the kind that survive a conversation with the business. Collectors chased 2,208 invoices *after* the payment had already arrived but before the cash had been applied — wasted calls, and an irritated customer each time, caused entirely by a lag inside the finance team rather than by the customer.
Seventy-two invoices were never sent at all, and they were paid on average a month and more late, which puts a number on something everyone assumes is harmless. And forty-six credit holds were released by someone who was neither a credit controller nor an AR manager — twenty-seven of them between ten at night and six in the morning.
Alongside those, the measurements a process owner wants: the touchless rate and whether it is improving, how often an invoice sent to the customer portal is actually opened within a day, how long a dispute takes to resolve, and whether invoices whose order was once on credit hold go on to pay later than the rest.
The SQL worth stealing
Four features carry most of the file. **Aggregate filters** build the milestone view in one pass. **Window functions** rank, number and roll three-month averages. **Macros** let a working-day count with the real public holidays be written once and called like a spreadsheet function. And expressing "none of these things happened" as "not in the list of invoices where any of them did" is the pattern behind both the touchless rate and the invoices that were paid with no chasing at all.
A handful of questions ask for two things at once — a month and an amount — and those queries build the answer as a single piece of text, which is a small reminder that SQL can format as well as calculate.
Where this sits next to the ledger
This is the same group whose receivables ledger is DATA DARE DD-ARC-002, published with its own forty answers in both SQL and pandas. Reading the two together is the exercise: the ledger says what is owed and how old it is, and the event log says why — which step took the time, which exception caused it, and who was involved.
That pairing is what a real improvement project looks like. The ledger gives you the size of the problem; the log gives you the cause. The findi360 AR Full-Scale Model course teaches this receivables family in Power BI and in Python side by side.
Inside the notebook
- Libraries — A cell that tells you which of the three libraries is missing before anything else runs.
- Point DuckDB at the files — Views over the event log, the invoices, four CSVs and two JSON files — plus three Excel files, registered from pandas.
- First look — The whole process in one table: every activity, how often it happens, and how many invoices it touched.
- Fix the data — The invoices with real dates, and the bank's remittance feed unnested from two levels of JSON.
- Five working views — One row per invoice with a column per milestone, the authority rule on credit holds, touchless invoices, working days with the real holidays, and unapplied cash at every month end.
- The answers, Q01 to Q50 — One query per question, each printing its answer, and a final list of all fifty.
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.
- One-off — you build it once, not again every month.
- Fixed structure — the same accounts, entities and layout each time.
- Small enough to check by eye — thousands of rows, not millions.
- One source — one ledger or one plan, not data scattered across systems and files.
- No live link needed — nobody expects it to update from the ledger by itself.
What measuring the process really costs in Excel
- Open a 559,254-row event log — which is past what a worksheet will hold comfortably — and give up on the full year.
- Pivot it to one row per invoice by hand, with a lookup per milestone and a column per step.
- Rebuild every cycle time whenever a new month of events arrives.
- Take the authority and after-hours checks on trust, because joining the user table is one lookup too many.
The same work, once it repeats
In DuckDB the log is never imported: one view turns it into one row per invoice, and every cycle time, drop-off rate and authority breach is a query that re-runs on next month's export unchanged.
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 opensWant 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 transformation and shared-service teams who need to measure a process, not describe it
- Credit control and collections managers looking for where the days actually go
- Internal audit teams testing authority limits and after-hours activity against a real log
- Anyone curious whether process mining needs specialist software — it does not
- Candidates preparing for the DATA DARE receivables challenges and the Silver Seal test
Frequently asked questions
Is this really process mining, without the specialist tools?
Yes, for the measurement half of it. An event log is a table; cycle times, drop-off rates, rework and authority breaches are all grouped aggregates over it. What a specialist tool adds is the automatic discovery and the visual process map. The findings in this notebook are the ones you would act on.
Do I need to know SQL already?
Only the shape of it. Every block has a short explanation in plain words before it, and the four features that do the heavy lifting each get a paragraph where they first appear.
What do I have to install?
One line: pip install duckdb pandas openpyxl. There is no server and no database file — DuckDB runs inside the notebook and reads the dataset files where they already are.
Will half a million events run on my laptop?
Comfortably. The log is a parquet file and DuckDB reads only the columns each query needs, so the whole notebook runs top to bottom in well under a minute on an ordinary machine.
Can I run this on my own ERP's log?
The milestone view in section 6.1 is the part that transfers: list your own activities in it and everything downstream follows. Getting the log out of the ERP in the first place is usually the harder half, and it is worth asking your IT team for a table of document number, activity, timestamp and user.
Are the answers in the file correct?
Every one of the fifty 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
- DATA DARE Mizan Manufacturing: Sales Up, Cash Slow — Accounts Receivable & Collections DD-ARC-001 · L1 — XLSX / ~10,000 rows Two Companies, Lump Payments and Cash Nobody Can Place — Accounts Receivable & Collections DD-ARC-002 · L2 — CSV / ~30,000 rows Mizan Group: The Life of a Customer Invoice - Order to Cash, Step by Step DD-ARC-003 · L3 — Parquet / ~500,000 rows
- DATA DRILL Test yourself — Power BI practice questions One question at a time, or a 50-question timed simulation.
- GUIDE AR ageing in Python The same work in Python, with tested code and its real output.
- COURSE Courses and free recordings Power BI, Python and finance courses for finance professionals.
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.
-
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.
-
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.
