Pay $500 from checking to a credit card and two statements record it. Checking shows $500 going out, and the card shows $500 coming in a day or two later. If both rows count, that one payment adds $500 to spending and $500 to income.


LedgerLift reads my bank and card statements. It runs on my laptop, turns statement PDFs and CSV files into one database, and shows the totals on a small dashboard. These are its main pages:
None of those totals should count the $500 payment twice. So before the dashboard adds anything up, LedgerLift has to notice when two rows are the same payment. That takes two decisions: which rows belong together, and what to count once they do.
How LedgerLift finds the pairs#
LedgerLift first rules out rows that can't be the same payment. The two rows must come from different accounts, with money leaving one and arriving in the other. By default, the amounts must be within one cent and the dates within five days.
Plenty of rows can pass those checks. A $500 debit might sit near two $500 credits, and only one of them is its partner. So each pair that passes gets a score, and the higher score wins:
def _score_candidate_pair(txn_a, txn_b, *, date_tolerance_days, amount_tolerance):
if (txn_a.institution, txn_a.account_name) == (txn_b.institution, txn_b.account_name):
return None
if txn_a.direction == txn_b.direction:
return None
if abs(abs(txn_a.amount) - abs(txn_b.amount)) > amount_tolerance:
return None
date_diff = abs((txn_a.transaction_date - txn_b.transaction_date).days)
if date_diff > date_tolerance_days:
return None
description_similarity = fuzz.token_set_ratio(txn_a.description_normalized, txn_b.description_normalized) / 100
ipc_mismatch = txn_a.is_internal_payment_candidate != txn_b.is_internal_payment_candidate
score = 1.0 - (0.1 * date_diff) - (0.2 if ipc_mismatch else 0.0)
score += 0.1 * description_similarity
return score, date_diff
Each row carries a flag that marks whether it looks like a card payment. Every pair starts at 1.0 and loses 0.1 for each day between the two dates, plus 0.2 if the flags don't match. Similar descriptions add at most 0.1.
LedgerLift takes the best pairs first and stops once the score falls below 0.6. A row can only be in one pair.
Taking the best pairs first is where the weights matter. When one row has two possible partners, the flag counts for more than the description. The description only decides when both candidates lose the same amount for days and flags.
The score puts its own limit on distance too. Each day costs 0.1 and a pair needs 0.6, so even with identical descriptions, two rows can be at most five days apart if the flags agree, the same as the check, and only three days if they don't. Each cell in the table runs from unrelated descriptions to identical ones. A score of exactly 0.6 still counts as a match.
| Days apart | Flags agree | Flags differ |
|---|---|---|
| 0 | 1.0 to 1.1 | 0.8 to 0.9 |
| 1 | 0.9 to 1.0 | 0.7 to 0.8 |
| 2 | 0.8 to 0.9 | 0.6 to 0.7 |
| 3 | 0.7 to 0.8 | 0.5 to 0.6 |
| 4 | 0.6 to 0.7 | 0.4 to 0.5 |
| 5 | 0.5 to 0.6 | 0.3 to 0.4 |
I picked the numbers in the formula by feel and tuned them by trial and error. If there was a deeper reason for 0.2, I've since lost it.
The Transfers page lists the pairs LedgerLift found. The $500 payment from the top is there, two days apart, and so is a $1,182.40 payment whose two rows landed on the same day.


Why both rows are left out#
Once LedgerLift has a pair, it still has to decide which of the two rows to count. Today it counts neither, but I got that wrong at first.
An earlier version kept the checking side of each pair and dropped the card side. That seemed reasonable, since the checking debit is when money actually left. Then the totals came out far too high. The purchases on the card had already been counted as expenses when they happened, so the kept debit counted the same money a second time.
A made-up example, not real totals: $500 of purchases on the card, then the $500 payment from the top of this post.
| Rule | Expenses | Income |
|---|---|---|
| Count both rows | $1,000 | $500 |
| Keep the checking debit (old) | $1,000 | $0 |
| Drop both rows (now) | $500 | $0 |
Now both rows are left out, because paying off a card isn't spending: the money only moved between two of my own accounts. The spending happened at checkout, and LedgerLift already counted it there.
The rows that can't pair#
All of this assumes both rows show up. The harder problem is the row whose partner never arrives, and I know of two ways that happens.
Some of my cash accounts are linked, and the bank moves money between them on its own. Those automatic moves show up on only one statement, so LedgerLift marks them as rows that will never get a pair.
The other case is a payment to a card whose old statements I don't have. The checking debit is all I have for that card, and since the purchases it paid for aren't in LedgerLift, nothing gets counted twice. So in that one case the dashboard still counts the payment as an expense. It's the only place the old keep-the-debit rule was right.







