Skip to content
Astera Technology

Why does a debit increase the cash reconciliation total?

Apply the export’s credit/debit direction before calculating net account movement.

Download complete case notes and answer keys ↓

Prepare the diagnostic input

The bank fixture stores every amount as a positive magnitude and carries direction in kind. Summing amount alone treats withdrawals as incoming cash. Translate the documented fixture direction into signed amounts before summing; do not infer direction from description text.

Use a fresh SQLite test database for the complete setup below. Every record is fictional; quantities are units and input monetary columns ending in cents use integer currency cents. Calculated averages may include fractions of a cent. Input previews include every table in this small fixture.

Synthetic input: bank_rows
idkindamount_cents
B1credit10000
B2debit3000
Download editable CSV ↓
Complete executable setup
CREATE TABLE bank_rows(id TEXT PRIMARY KEY,kind TEXT,amount_cents INTEGER);
INSERT INTO bank_rows VALUES ('B1','credit',10000),('B2','debit',3000);

Reproduce the misleading result and correct it

Misleading query: use for diagnosis only
SELECT SUM(amount_cents) AS net_change_cents FROM bank_rows;
Executed misleading result
net_change_cents
13000
Download editable CSV ↓
Corrected SQLite query
SELECT SUM(CASE WHEN kind='credit' THEN amount_cents WHEN kind='debit' THEN -amount_cents END) AS net_change_cents FROM bank_rows;
Executed corrected result
net_change_cents
7000
Download editable CSV ↓

A 10000-cent credit and 3000-cent debit change the account by 7000 cents, not 13000. This is account movement, not invoice revenue or a closing balance. An opening balance would be needed to derive closing cash.

Check the boundary before applying the fix

Add a 7000-cent debit. The net movement becomes zero, showing that zero can represent offsetting inflows and outflows rather than no activity.

For the boundary test, recreate the complete setup in another fresh synthetic database, apply only the change below, then rerun the corrected query. Do not apply a test mutation to a live system.

Boundary change in the fresh fixture
INSERT INTO bank_rows VALUES ('B3','debit',7000);
Executed boundary result from the corrected query
net_change_cents
0
Download editable CSV ↓

The two kind values are fixture rules, not universal bank-code meanings. Unknown kinds produce NULL in the CASE and must be separately flagged before relying on totals.

The displayed bad, corrected and boundary results were executed in SQLite and checked against separately authored expected rows. This demonstrates the stated fixture only; it does not test other database engines, production performance or your live schema.

Related resources