Marketplace sellers download the same reports again and again: this month, last month, a corrected version. If an import simply appends rows, a reimbursement that appears in two downloads is counted twice and the 'still owed' figure goes wrong in the seller's favour, which is the worst direction to be wrong in.
Key every row by what the source already gives you
Most reports carry identifiers: a ledger reference, a shipment or removal order ID, a product SKU and a date. A key made from them makes the import idempotent: importing the same file twice adds nothing.
// idempotent import: key each record by its source identifiers const seen = new Map(); function importRows(rows) { let added = 0; for (const r of rows) { const key = [r.kind, r.reportId, r.fnsku, r.date].join('|'); if (seen.has(key)) continue; seen.set(key, r); added++; } return added; } function openUnits(caseId) { let lost = 0, restored = 0, reimbursed = 0; for (const r of seen.values()) { if (r.caseId !== caseId) continue; if (r.kind === 'lost') lost += r.units; if (r.kind === 'restored') restored += r.units; if (r.kind === 'reimbursed') reimbursed += r.units; } return lost - restored - reimbursed; } const rows = [ { kind: 'lost', reportId: 'L-881', fnsku: 'X00ABC', date: '2026-10-02', units: 12, caseId: 'L-881' }, { kind: 'restored', reportId: 'L-881', fnsku: 'X00ABC', date: '2026-10-19', units: 5, caseId: 'L-881' }, { kind: 'reimbursed', reportId: 'R-5521', fnsku: 'X00ABC', date: '2026-11-03', units: 4, caseId: 'L-881' }, ]; console.log(importRows(rows), importRows(rows), openUnits('L-881')); Output: 3 0 3. The first import adds three rows, the second adds none, and the case still shows 3 open units (12 lost − 5 restored − 4 reimbursed).
Rules that keep it honest
- Link a reimbursement to a loss only through a direct reference, never by 'same SKU, similar date'. Anything ambiguous waits for a person to confirm.
- Keep units and money separate. 'Unpaid units' and 'paid, but at a value you dispute' are different questions with different evidence.
- If restored plus reimbursed units exceed lost units, flag it instead of letting the open count go negative.
We use the same approach in FBA Inventory Loss & Reimbursement Desk (paid, with a free demo; independent tool, not affiliated with Amazon).
