I do this in one of my applications to generate an "aged receivables"
report, which sums according to how old a charge is and shows the balances
for each customer for each time window. (I admit that I didn't know about
the Partition function when I wrote this part of the application - I think
it would simplify things a lot if I had used it).
Assuming that you have data in the tables that relates each payment and each
charge back to a specific invoice, and that each invoice relates back to a
specific customer, my setup uses three cascading queries.
The first provides a sum of the payments made for each invoice, providing
these outputs:
InvoiceNumber
TotalPaymentsMadeToDate
The second query uses the first query and the table with "total amount due"
for each invoice to get a list of all invoices, their amounts that were due
on the invoice, and the total amount of payments made for that invoice.
Outputs are
InvoiceNumber
InvoiceDate
OriginalAmountDue
TotalPaymentsMadeToDate
The third query then uses the second query to build the data for the final
report for each invoice - namely, the invoice number, customer's
information, the total amount of money that was billed on the invoice, the
total amount that has been paid on the invoice, the unpaid amount remaining
for the invoice, and a series of calculated fields that look at the invoice
date and compare to the date of the report to calculate how many days have
passed -- and if the number of days fits within that window (e.g., 0 - 30
days; 31 - 60 days), displays the "unpaid" amount in that field, else it
displays a Null value.
The report that is run from the third query then sums the data as desired
for the outputted report.
Not overly complex, but it did take me a while to work it all out. Partition
function would be used in place of my calculated fields in the third query.
--
Ken Snell
<MS ACCESS MVP>
Dale Fye said:
Gary,
From my perspective, you may be missing the relationship between a payment
and a specific charge. Without this, your (Chrgs-Pmts) figure for a
particular time period could be negative (no charges, but payments
received). You also don't indicate whether you want to only display the
PatientFee and Patient PmtType in your computations. Furthuremore, I
think your structure overlooks the potential (frequent in my case)
instance where the insurance company denies part or all of the claim; what
do you do then?
Let me think on this one for a while and I'll get back to you. In the
meantime, maybe someone else has already dealt with this situation and can
respond.
Dale
Gary B said:
Updated Table Structure... sorry:
tbl Patients: PatKey(pk); PatientNo; PatientName
tblCharges: ChrgKey(pk); PatKey(fk); ChrgDate
tblServices: ServsKey(pk); ChrgKey(fk), PatKey(fk); PatientFee;
InsuranceFee
tblPayments: PmtKey(pk); PatKey(fk); PmtType(1=PatPmt; 2=InsPmt);
PmtDate; PmtAmount
I want to display PatientNo, PatientName, [00-30](Chrgs-Pmts),
[31-60](Chrgs-Pmts), [61-90](Chrgs-Pmts), [Over-90](Chrgs-Pmts)
[00-30](Chrgs-Pmts) = I want this column to be the monitary value of all
(Chrgs - Pmts) that occurred between 0 and 30 days ago;
[31-60](Chrgs-Pmts) = I want this column to be the monitary value of all
(Chrgs - Pmts) that occurred between 31 and 60 days ago;
I am lousy at expressing myself!
Thanks again!