This is also a problem for accountants, trying to do “account reconciliation” to determine which transactions contribute to a given balance.
I made a simple tool that does this client-side for an accountant friend a while ago: https://reconciliation.spcdx.com/
(Warning: runtimes do quickly scale, due to the time complexity described above)