Hi,
I need to calculate the time between deposits and withdrawals in a savings account. I have a table with deposits and a table with withdrawals. The difficulty lies in matching up the two tables based on first in, first out logic rather than a primary & foreign key.
As an example, if a customer deposits $500 in January 2010, and withdraws $500 in January 2011 the time attached to that $500 is 1.00 years. Ultimately, the script needs to calculate the duration of each deposit in each account, which can then be aggregated into deposit categories like money market accounts and IRA accounts.
The difficult part of the script is matching up deposits and withdrawals on a first in, first out basis. Plus, the amount of one withdrawal usually doesn’t match the amount of its matching deposit. The good news is that deposits are always >= withdrawals, in total.
An example with starting data and what the end result could look like is attached.
Thanks in advance for your help!
Ted Price
Colorado Springs, CO