Accounting Analytics: An Integrated Approach
Part III of V: Accounting Analytics with SQL
Chapter 4 of 4 in this Part
Restrict the ledger rows to the document type, then match the document ID.
SELECT 'Posting with no payment' AS Test, ...
FROM GLEntry LEFT JOIN PayrollPayment ...
UNION ALL
SELECT 'Invoice with no posting', ...
FROM SalesInvoice LEFT JOIN GLEntry ...Which test finds each problem?
Check that:
Exception, accrual or risk?
Check that:
Isolated exception or systematic pattern?
Check that:
printf('%.15e', Amount) writes the first significant digit firstLOG10(1 + 1.0 / Digit) gives Benford’s expectation for each digitb.DisbursementID > a.DisbursementID, a row pairs with itselfTable 12.1 · The audit query library of this chapter
| Tests | What they test | Technique | Expected result |
|---|---|---|---|
| L1–L2 | Journal entries and manufacturing payroll against the ledger | Aggregates, scalar subqueries | Agree to the cent |
| L3–L4 | Postings traced to payments, and invoices to postings; unpaid registers | Anti-joins, UNION ALL | No rows |
| L5–L6 | Revenue outside the year of delivery; shipments never invoiced | CTEs, CASE, anti-join | No rows |
| L7–L8 | Pay periods across a year-end; accrued payroll | Derived table, aggregates | Unpaid wages accrued |
Table 12.1 · The audit query library of this chapter
| Tests | What they test | Technique | Expected result |
|---|---|---|---|
| P1–P3 | Three-way match, price tolerance, receipts not invoiced | CTEs, CASE, tolerances | No exceptions; within rounding of account 2020 |
| P4–P6 | Purchase order approvals and their concentration | UNION ALL, joins to Employee | No rows; approval shared |
| H1–H3 | Time records profiled; hours clocked, recorded, and paid; the hours of 2024 | Aggregates, CTEs, CASE | Complete; equal |
| H4–H5 | Whose time was paid; pay recalculated from hours and rates | Joins, UNION ALL, CTE | No rows; within a cent |
| H6–H8 | Overtime approvals; days on which everyone clocked the same hours | CASE, left joins, CTE | Approved; no such days |
| H9–H10 | Direct time dated after its operation ended | Inner join to operations, left join to a CTE | A small share |
Audit query library · Concentration of approval · Cutoff · Existence and completeness tests · Full-population testing · Goods received not invoiced · Price tolerance · Self-join · Substantive analytical procedure · Three-way match · UNION ALL · Unrecorded liability
Next: Comprehensive Case: Planning the Plant’s Hours for 2027
These slides accompany Accounting Analytics: An Integrated Approach, licensed under CC BY-SA 4.0. Every figure and table comes from the chapter:
https://aa.accountinganalyticshub.com/chapters/12-sql-audit-analytics/chapter.html
Chapter 12 · Audit Analytics in SQL