Combination

Journal entries where debit does not equal credit

List the entries whose debit and credit totals differ: take the unique entry numbers, total debit and credit per entry with SUMIFS, and keep the unequal ones with FILTER over HSTACK, all named in one LET.

Functions used:LETUNIQUESUMIFSFILTERHSTACKExcel 2024 or later (This combination needs Excel 2024 or later)

Difficulty rating 4 of 5

Worked example

Entries that do not balance

Scenario

For Veldhuis Installatie BV you received the journal lines of the first quarter of 2025 from the XAF auditfile. Before you rely on the ledger you check that debit equals credit per entry. You want one formula that lists every entry that does not balance, with its debit, credit and difference.

The data

Sheet excerpt: F2 holds the formula
RowABCDEFGHIJKL
1Entry no.AccountDebitCreditEntry no.25-0415
225-041213001300€12,100.00€ 12.100,00€0.00€ 0,0025-0415=LET(e, UNIQUE(A2:A9), debit, SUMIFS(C2:C9, A2:A9, e), credit, SUMIFS(D2:D9, A2:A9, e), FILTER(HSTACK(e, debit, credit, debit-credit), debit<>credit, "All entries balance"))=LET(e; UNIQUE(A2:A9); debit; SUMIFS(C2:C9; A2:A9; e); credit; SUMIFS(D2:D9; A2:A9; e); FILTER(HSTACK(e; debit; credit; debit-credit); debit<>credit; "All entries balance"))€3,500.00€ 3.500,00€3,050.00€ 3.050,00€450.00€ 450,00
325-041280008000€0.00€ 0,00€10,000.00€ 10.000,0025-0431€5,200.00€ 5.200,00€0.00€ 0,00€5,200.00€ 5.200,00
425-041218001800€0.00€ 0,00€2,100.00€ 2.100,00
525-041545004500€3,500.00€ 3.500,00€0.00€ 0,00
625-041516001600€0.00€ 0,00€3,050.00€ 3.050,00
725-042011001100€8,400.00€ 8.400,00€0.00€ 0,00
825-042013001300€0.00€ 0,00€8,400.00€ 8.400,00
925-043140004000€5,200.00€ 5.200,00€0.00€ 0,00
10
Formula cell (F2)InputSpilled result

Formula in F2

=LET(e, UNIQUE(A2:A9), debit, SUMIFS(C2:C9, A2:A9, e), credit, SUMIFS(D2:D9, A2:A9, e), FILTER(HSTACK(e, debit, credit, debit-credit), debit<>credit, "All entries balance"))
=LET(e; UNIQUE(A2:A9); debit; SUMIFS(C2:C9; A2:A9; e); credit; SUMIFS(D2:D9; A2:A9; e); FILTER(HSTACK(e; debit; credit; debit-credit); debit<>credit; "All entries balance"))

Result: 25-0415 | €3,500.00 | €3,050.00 | €450.00 / 25-0431 | €5,200.00 | €0.00 | €5,200.0025-0415 | € 3.500,00 | € 3.050,00 | € 450,00 / 25-0431 | € 5.200,00 | € 0,00 | € 5.200,00

How the pieces fit together

Watch out: Amounts with decimals can differ by a fraction of a cent through floating point arithmetic, so debit<>credit may flag an entry that balances in practice. Compare the rounded difference instead (see the variation with ROUND).

The formula taken apart, from the inside out. Each part can be typed into its own cell to see what it returns.

  1. =UNIQUE(A2:A9)
    =UNIQUE(A2:A9)

    The entry numbers once each, in order of first appearance: 25-0412, 25-0415, 25-0420, 25-0431. Eight journal lines become four entries.

  2. =SUMIFS(C2:C9, A2:A9, UNIQUE(A2:A9))
    =SUMIFS(C2:C9; A2:A9; UNIQUE(A2:A9))

    Total debit per entry. Because the criteria argument is a column of four entry numbers, SUMIFS returns four totals: 12,100, 3,500, 8,400 and 5,200.

  3. =SUMIFS(D2:D9, A2:A9, UNIQUE(A2:A9))
    =SUMIFS(D2:D9; A2:A9; UNIQUE(A2:A9))

    Total credit per entry in the same order: 10,000 + 2,100 = 12,100, then 3,050, 8,400 and 0.

  4. =SUMIFS(C2:C9, A2:A9, UNIQUE(A2:A9)) - SUMIFS(D2:D9, A2:A9, UNIQUE(A2:A9))
    =SUMIFS(C2:C9; A2:A9; UNIQUE(A2:A9)) - SUMIFS(D2:D9; A2:A9; UNIQUE(A2:A9))

    Debit minus credit per entry: 0, 450, 0 and 5,200. Every value other than 0 is an entry that does not balance.

  5. =LET(e, UNIQUE(A2:A9), debit, SUMIFS(C2:C9, A2:A9, e), credit, SUMIFS(D2:D9, A2:A9, e), FILTER(HSTACK(e, debit, credit, debit-credit), debit<>credit, "All entries balance"))
    =LET(e; UNIQUE(A2:A9); debit; SUMIFS(C2:C9; A2:A9; e); credit; SUMIFS(D2:D9; A2:A9; e); FILTER(HSTACK(e; debit; credit; debit-credit); debit<>credit; "All entries balance"))

    LET names the entries (e), the debit totals (debit) and the credit totals (credit) once.

    HSTACK puts entry, debit, credit and difference side by side in a 4 by 4 grid, and FILTER keeps the rows where debit<>credit: entries 25-0415 and 25-0431. If every entry balanced, the message would show instead.

Step by step

  1. e = UNIQUE(A2:A9) gives the four entries 25-0412, 25-0415, 25-0420 and 25-0431.
  2. debit = SUMIFS(C2:C9, A2:A9, e) totals the debit per entry:

    • 25-0412: 12,10012.100
    • 25-0415: 3,5003.500
    • 25-0420: 8,4008.400
    • 25-0431: 5,2005.200
  3. credit = SUMIFS(D2:D9, A2:A9, e) totals the credit per entry:

    • 25-0412: 10,00010.000 + 2,1002.100 = 12,10012.100
    • 25-0415: 3,0503.050
    • 25-0420: 8,4008.400
    • 25-0431: 0 (that entry has no credit line)
  4. debit-credit gives the differences: 12,10012.100 - 12,10012.100 = 0, 3,5003.500 - 3,0503.050 = 450, 8,4008.400 - 8,4008.400 = 0 and 5,2005.200 - 0 = 5,2005.200.
  5. HSTACK(e, debit, credit, debit-credit) places the four columns side by side: a grid of 4 rows and 4 columns, one row per entry.
  6. debit<>credit is FALSE, TRUE, FALSE, TRUE, so FILTER keeps rows 2 and 4: 25-0415 (3,5003.500 / 3,0503.050 / 450) and 25-0431 (5,2005.200 / 0 / 5,2005.200). The result fills F2:I3.

Why it works

SUMIFS accepts a whole column of criteria and returns one total per criterion, so UNIQUE and SUMIFS together give one debit and one credit total per entry without helper columns.

LET names those three results once, so debit and credit are used twice (in the grid and in the test) without being calculated twice. FILTER can then test debit<>credit against the rows of the HSTACK grid, because both have one row per entry.

Watch out for

  • An entry that is missing a line altogether, such as 25-0431 here, shows a credit of 0 and is caught. But an entry with equal debit and credit on the wrong accounts balances and is not flagged: this test checks the totals, not the accounts.
  • If some lines carry a trailing space or inconsistent formatting in the entry number (for example "25-0412 " next to "25-0412"), UNIQUE lists the entry twice, and SUMIFS counts only the lines that match each exact form, so each half looks unbalanced. Clean column A with TRIM first.

Variations

=LET(e, UNIQUE(A2:A9), debit, SUMIFS(C2:C9, A2:A9, e), credit, SUMIFS(D2:D9, A2:A9, e), FILTER(HSTACK(e, debit, credit, debit-credit), ROUND(debit-credit, 2)<>0, "All entries balance"))
=LET(e; UNIQUE(A2:A9); debit; SUMIFS(C2:C9; A2:A9; e); credit; SUMIFS(D2:D9; A2:A9; e); FILTER(HSTACK(e; debit; credit; debit-credit); ROUND(debit-credit; 2)<>0; "All entries balance"))

Tests the difference rounded to two decimals, so tiny floating point differences are ignored. Same two entries here.

=SUMIF(A2:A9, K1, C2:C9) - SUMIF(A2:A9, K1, D2:D9)
=SUMIF(A2:A9; K1; C2:C9) - SUMIF(A2:A9; K1; D2:D9)

The older way, one entry at a time: type an entry number in K1 and get its difference (450 for 25-0415). It works in every Excel version, but you must repeat it for each entry.

All combinations