• I don't want to confuse the issue but I come from an accounting background and I very seldom saw the payments on invoices match to the penny unless they were made on one payment.  Do you have a front-end process to issue a credit/debit memo for small under- or over-payments?  If not, you may need to adjust the "=0" to something like "< 1.00 or > 1.00" to account for small differences.

    Mr. Coleman's solution is straightfoward and elegant, but I'm guessing it won't do what you need.

    The solution works only when all credits in the account equal all debits (as stated in the original post).  However the underlying assumption in your original question is that a new invoice won't be posted until the previous invoice is paid in full (i.e. credits = debits).  For instance, in the first group (STH002) the algorithm would work if run between 5/27 (after the credit) and before the 6/28 debit was recorded, but would not workif it was run for the first time after 6/28.

    To put it simply, the only time the update takes place is when all debits = all credits.  In real life, you are probably posting new debits before receiving credits for the existing debits and the two totals will almost never equal one another.

    Without document numbers, it seems you are stuck with an open balance method of reporting rather than applying specific credits to specific debits.  Is there any way to add another reference field?