Establish what one row represents
A closing index can have one row per invoice in one table and one row per document in another. Linking them repeats an invoice's amount whenever that invoice has several linked documents. Summing the expanded rows then answers a different question from summing invoices once.
Practice entirely on these invented non-sensitive paper tables in one fictional currency, CU. There are no real invoices, people, accounts, files or private organizations. No software or actual file access is required. Index links establish no document substance, payment, authenticity, eligible cost, actual evidence completeness or closing permission.
1. Preserve both complete tables
The exercise stipulates exactly one distinct parent row per nonblank invoice ID, with its amount recorded once per invoice. I-A and I-B are different invoices despite their equal amounts. The complete child index has one row per document ID, each with one invoice reference.
Parent table P
| Invoice ID | Amount CU |
|---|---|
| I-A | 40 |
| I-B | 40 |
| I-C | 20 |
Child index C
| Document ID | Referenced invoice ID |
|---|---|
| D-1 | I-A |
| D-2 | I-A |
| D-3 | I-B |
| D-4 | I-X |
I-X is absent from P. There are no other child records within this toy index. That stipulated completeness concerns this exercise only; it is no finding about actual organizational records.
Before linking, check the claimed row meaning, identifier uniqueness and nonblank parent keys. If these prerequisites fail in another task, resolve them rather than assuming every repeated parent key is a legitimate second document.
2. Expand matching pairs without changing invoice grain
Rule R makes one row for every parent-child pair with equal invoice IDs, carrying the parent amount onto each pair:
| Invoice | Matching document | Repeated parent amount CU |
|---|---|---|
| I-A | D-1 | 40 |
| I-A | D-2 | 40 |
| I-B | D-3 | 40 |
There are three matching rows and their displayed amounts sum to 120. I-A contributes its 40 twice. The original invoice total remains 40 + 40 + 20 = 100 CU. Nothing added a new invoice or changed a parent amount.
PostgreSQL's table-expression documentation supplies the matching-pair concept; its separate key documentation supports checking identity prerequisites. These are paper analogies, without code, database repair or runtime instructions. The two sections belong to one manual.
3. Retain unmatched parents and orphan references separately
A parent-preserving expansion retains the three matched rows and adds:
| Unmatched parent | Child status | Parent amount CU |
|---|---|---|
| I-C | UNKNOWN: no matching child in this complete index | 20 |
This expansion has four rows, displayed sum 120 + 20 = 140. Keeping every parent does not prevent repeated I-A amounts. It still is not an invoice total.
Separately list D-4 -> I-X as an orphan reference: its referenced parent is absent from P. Do not invent I-X's amount, match it to an equal amount, or conceal it by dropping the row.
Coverage within the original toy index is I-A two linked documents, I-B one and I-C zero. Zero indexed links is not proof that an actual invoice lacks evidence. Conversely, a link is not proof its document is authentic, complete or acceptable.
4. Aggregate once per validated parent identity
Return to P's three validated invoice IDs to obtain 100 CU. Keep the child coverage and orphan list alongside that total as separate information.
Do not “fix” repetition by summing only distinct amount values. P's distinct numeric values are 40 and 20, whose sum 60 wrongly collapses the different I-A and I-B invoices. Identity distinguishes invoices; equal money values do not identify duplicates.
Fictional Draft D says the matching total 120 proves invoices rose by 20, repeated amount 40 should be removed, and counting all child records proves complete authentic evidence and permission to delete records. Each leap fails: expansion repeats amounts; equal amounts can belong to different invoices; linkage is not evidence acceptance; and an index grants no deletion authority.
5. Add an attachment without adding invoice value
In separate Case B, keep P and original C, adding only D-5 -> I-A. No invoice amount changes.
The matching expansion is now I-A/D-1, I-A/D-2, I-A/D-5 and I-B/D-3: four rows x 40 = 160 CU. Parent-preserving expansion also retains I-C/UNKNOWN/20: five rows, displayed sum 180 CU. The parent invoice total remains 100 CU.
This is the expected consequence of a new child link, not evidence that invoices rose. The pandas merge guide discusses duplicate-key enlargement and separate uniqueness checks; no installation, performance claim or source example is imported here.
6. Withdraw one reference without guessing its parent
In separate Case U, restore original P and its four-child C. Withdraw only D-3's invoice reference; no replacement is supplied. D-1/D-2 still reference I-A and D-4 still references I-X.
Two known matching pairs remain, carrying 40 + 40 = 80 CU. The full matching sum is UNKNOWN:
| Possible missing D-3 reference | Full matching sum CU |
|---|---|
| I-A or I-B | 120 |
| I-C | 100 |
| Outside P or no valid reference | 80 |
These are compatible possibilities, not recovered values. I-A has at least two known links, possibly another. I-B and I-C coverage remain unresolved. D-4 remains a known orphan. The unchanged parent total is still 100; missing child linkage does not erase it.
7. Hand off exact evidence questions
Keep original P/C, scenario labels, expansion working, parent total, coverage and orphan status together. Ask the records owner to establish D-3's missing reference and investigate D-4's absent parent without overwriting the supplied history. Actual identity corrections, evidence acceptance, payments, eligibility and retention or disposal decisions require their own authorized owners and evidence.
CARE's document-retention guidance supports a usable continuing trail after project completion, with institutional scope. It supplies no universal retention duration or permission to delete. Completing this arithmetic exercise changes no files or financial records.
Related: management accounts and reconciliation handoff.
