General Ledger Analysis in SQL — 50 Worked Answers on 1.17 Million Journal Lines (DuckDB)
This is the set that proves the point about SQL and finance data. A million journal lines across three companies and four years, with the chart of accounts, the reporting lines it rolls into, the cost centres, the parties, the users and their approval limits, the close calendar, the budget and reforecast, the exported trial balance and the bank statements as the bank sent them. From that the notebook does the three jobs a financial controller actually does — build the statements, close the books, check the controls — in fifty queries, each one short enough to read. 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-GLT-003 · 1,172,802 journal lines · three companies · 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
Debits, credits and the one trick that makes the SQL simple
A ledger keeps debits and credits in separate columns, which is right for a ledger and awkward for arithmetic. The move that unlocks everything is to make one signed column — and to make two of them, for the two jobs they do.
Credit minus debit gives income positive: revenue comes out positive, costs come out negative, and a subtotal is a plain sum with no sign rules and no lookup table. Gross profit is revenue plus cost of sales. EBITDA is five lines added up. Profit before tax is eight. Debit minus credit gives the other direction, which is what a cash or receivables balance needs. Pick the one that matches the side the account naturally sits on, and the rest of the SQL stays short.
Join the chart of accounts once at the same time, and no later query ever has to name an account number: it asks for cost of sales and gets it, and when the chart changes nothing downstream breaks.
Period 13, and other things only accountants know
The period key runs 202501 to 202512 and then 202513 — period 13, where the audit adjustments go. It belongs to the year, so a calendar-year figure has to include it and a twelve-month one must not, and the question text says which. Getting it the wrong way round moves the gross profit bridge by a few thousand, which is exactly the kind of error that survives a review because the number still looks plausible.
Fiscal years that are not calendar years are here too: one of the three companies runs April to March, so its year is a period range rather than a `YEAR()` call. And the close calendar records when each period's trial balance was exported, which makes a question possible that most systems cannot answer — how many journals were entered after the numbers had already been reported.
Four dates on one invoice
Every supplier invoice in this ledger carries a document date, a posting date, a due date and an entry date, and in December they disagree. Asking what December's invoices came to on each of those four bases gives four answers spread across nearly a million and a half, and that spread is the year-end cut-off problem in a single number.
It is the same data four times, which is the point: the question "how much did we buy in December" has no single answer until you say which date you mean. The notebook asks it four ways in four nearly identical queries, which is the clearest way to show a non-accountant why the close takes as long as it does.
Reconciling to the trial balance and to the bank
Two reconciliations, both of which should come to nothing and neither of which does. The exported trial balance for one company and period disagrees with the posted journal lines behind it, because journals arrived after the export. And the ledger's cash account disagrees with the bank's own running balance, in both companies tested.
The bank statements are also where this notebook meets a practical snag worth knowing about: the file is one JSON object of about 18 MB, and DuckDB refuses to read a single object larger than 16 MB unless you tell it otherwise. The fix is one argument, and it is better to meet it here than at half past five on a reporting day.
The controls, in one view
The file is lines; most control questions are about journals. Rolling the lines up once into a journal header — who entered it and when, who approved it, what it totals — turns eight separate audit tests into one-liners: entered at the weekend, entered in the middle of the night, approved by the same person who posted it, approved within two minutes of being typed, posted by someone who had already left, posted above the poster's own approval limit.
These are the tests an internal audit team asks for every year and rarely gets run over the whole population. Here they run over all 1.17 million lines in under a second, and each number is a conversation with a named person.
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 journal lines, the dimensions, the trial balance and two JSON files — plus two Excel files, registered from pandas.
- First look — The reporting-line structure, the journal sources, and a check that the ledger balances in every company and year.
- Fix the data — Join the chart of accounts, build the two signed columns, and read a bank statement bigger than DuckDB's default object limit.
- Four working views — The P&L in one view, one row per journal, supplier invoices with their duplicates, and the bank's closing balance each day.
- 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 building the group P&L really costs in Excel
- Open 1,172,802 journal lines — which no worksheet will hold — so start from someone's extract instead and hope it is complete.
- Map every account to a reporting line with a lookup column, and re-check it when the chart of accounts changes.
- Rebuild the sign handling for income against cost, by hand, in every subtotal.
- Run the control tests on a sample, because the population is out of reach.
The same work, once it repeats
In DuckDB the ledger is never imported: the chart of accounts is joined once, the P&L is a single GROUP BY over every line, and the control tests cover the whole population rather than a sample.
DuckDB still needs your judgement where the data is new — but everything after that repeats by itself.
Learn it on findi360: IFRS 18 Adjustments in Power BI
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
- Financial controllers and reporting accountants who rebuild the same statements every month
- Group reporting teams dealing with fiscal years, period 13 and three sets of books
- Internal and external audit teams who want their control tests run over the whole population
- Accountants moving from spreadsheets to SQL who want a ledger rather than a toy database to learn on
- Candidates preparing for the DATA DARE general ledger challenges and the Silver Seal test
Frequently asked questions
Do I need to know SQL already?
Only the shape of it. Every block has a short explanation in plain words before it. The two sections that matter most — the signed columns and the P&L view — are explained from first principles, because everything else in the file depends on them.
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.
Will a million journal lines run on my laptop?
Yes, comfortably. The ledger is a parquet file and DuckDB reads only the columns each query needs; the full P&L is one GROUP BY and returns in well under a second.
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. The bank statement file needs the maximum_object_size argument on either version, and the notebook explains why where it first uses it.
Why build the P&L from journal lines instead of using the trial balance?
Because the trial balance is a snapshot someone exported, and this ledger proves the point: for one company and period the two disagree, because journals were posted after the export. Building from the lines means you can always see what changed and when.
Can I run these queries on my own ledger?
The structure transfers directly, and this is the set to use as a template. You need your journal lines, your chart of accounts with a reporting line on each account, and your user table. The signed columns and the P&L view are then almost unchanged, and the control tests need only your own column names.
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 Retail: Sales Up, Profit Down — Journals, Trial Balance and Budget DD-GLT-001 · L1 — XLSX / ~10,000 rows Three Companies, Four Dates, One Close — GL, Trial Balance, Bank and Budget DD-GLT-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 Trial balance 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
-
IFRS 18 Financial Statements Model
A retailer's general ledger becomes a live trial balance and a full set of financial statements, with the profit or loss presented under IAS 1 as applied today and under IFRS 18 from 1 January 2027. Same profit, different operating profit.
-
Trial Balance in Python — Jupyter Notebook
The general ledger worked end to end in pandas: a trial balance that proves it balances, a profit and loss account by reporting line, actuals against budget, and a gross profit bridge that explains why profit grew less than sales.
-
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.
