views:

48

answers:

1

I have three tables:

Charges
Payments
Adjustments

Each has a value, called Amount. There are no allocations done on this data, we are assuming the oldest Payments are paying the oldest Charges or Adjustments. Each Amount could be +ve or -ve.

I need to produce a report which shows the age of the debt, based on the current balance being in debt, where the balance is the sum of each Amount in all tables. However, the age of the debt must be the Age of the current debt. If an account was in debit in October, but was zeroed in November and then in Debit in February, the Age of the Debt would be February. In need to provide a 30, 60, 90 day breakdown of each account whose balance is outstanding.

Sorry if this isn't clear, but if you've done it before you'll know what I mean. Any pointers?

A: 

Just been playing with a pen and paper. Is this as simple as:

Amnt Current Debt at Time = Sum(Debits to Time) - Sum (All Credits)

So in SQL: Convert All +ve Charges, -ve Adjustments or -ve Payments to Debits (UNION) Convert all -ve Charges, +ve Adjustments or +ve Payments to Credits (UNION) For each of your age points, get the Sum of Debits to that point and subtract all of the credits for all time. (SUM and GROUP BY)

Any problems with this?

Molloch
"Any problems with this?" Yes: Amnt Current Debt at Time = Sum(Debits to Time) - Sum (All Credits **to Time**). A credit amount that was received this week can't be deducted from a debit balance at the end of last month, when trying to find the total balance as at the end of last month - because it hadn't been received then.
Mark Bannister
Correct, but I am not trying to find the Balance at the end of last month, I am trying to find the Age of the Current Balance, or Aged Debt. I want to answer the question: This Account has a debit balance, how much of the Debit is 30, 60 or 90 days old? I can't just take the balance at a point in time, incase that balance has fluctuated into debit and credit over time.
Molloch
Quite so - in order to find the age of the debt, you need to find the last point in time when the account balance was in credit; the date of the next charge/payment/adjustment record is therefore the point at which it tipped into debt, ie. is the age of the debt. This is quite easy to find if you have a balance history, but is somewhat harder if you don't.
Mark Bannister
Come to think of it, the date on which the total debit values to date exceeded all credits *would* also be the last point at which the account tipped into debt, ie. the age of the debt. Using this method requires you to derive the total debit values to transaction date for all debit transactions, and the total of all credit values - it would work, but it would be much easier to use a balance history (if you've got one).
Mark Bannister