Build Daily Closing Balances per Account and Currency From Ledger Entries
Last updated: November 29, 2026
Quick Overview
Given a ledger_entries table (account_id, currency, amount_minor, posted_at, status), produce one row per account, currency and calendar day from the first activity onward with that day's net movement and closing balance, including days with no activity.
Airwallex
November 29, 20260
0
0 solved
Given a ledger_entries table (account_id, currency, amount_minor, posted_at, status), produce one row per account, currency and calendar day from the first activity onward with that day's net movement and closing balance, including days with no activity.
A typical data engineering screen for a multi-currency wallet business like Airwallex, where finance, treasury and regulatory reports all start from daily balances per currency. The interviewer is checking that you never sum across currencies, fill gap days, exclude reversed entries and pin down a time zone for the day boundary.
What the Interviewer Expects
- Keeps account and currency together as the balance key
- Filters to posted entries only and explains reversals
- Builds a date spine so quiet days still carry the prior balance
- Uses a running window sum ordered by day
- States the time zone that defines a business day
- Validates against a known balance snapshot
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- Finance wants balances in each customer's local time zone. What changes?
- How would you make this incremental for a table with billions of rows?
- How do you report a USD-equivalent total, and which FX rate do you use?
- How would you detect a day where the computed balance disagrees with the ledger service?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
amount_minor is a signed integer (credits positive, debits negative) in the entry's currency. status can be posted, pending or reversed; only posted entries affect the balance, and a reversa...
Approach
- Aggregate posted entries to one net movement per (account, currency, day).
- Find each pair's first active day.
- Cross the pairs with every calendar day from that first day forward (the spine). ...