Originally Posted by
victor
Attached is a database with two tables. i would like to calculate the difference between field amount(table invoice) and amount paid(payments). the problem is when i linked the two tables using patient ID it replicates the amount paid more then the number. say receipt 24 will appear for each column of patient id in the invoice table
VICTOR,
your data is very much disoriented. it needs to be normalized. try this to fix your current problem though:
Code:
SELECT DISTINCT
Invoice.[Patient ID],
NZ(DSUM("[QUANTITY] * [PRICE]", "INVOICE",
"[PATIENT ID] = " & [PATIENT ID]), 0) AS TotalPurchased,
NZ(DSUM("[AMOUNT PAID]", "PAYMENTS",
"[PATIENT ID] = " & [PATIENT ID]), 0) AS TotalPaid,
[TotalPurchased] - [TotalPaid] AS CurrentBalance
FROM Invoice;