If I am understanding your database structure properly, you have three tables Vendors
, Invoices
and Invoice Line Items
. Your Invoice Line Items
table has a field Cost
on it. Your Invoices
table has a flag (field) Vendor Paid
on it. And on the Vendors
table you'd like a sum of the total cost and a sum of the unpaid cost.
These fields are related in one-to-many relationships as follows:
Vendors --< Invoices --< Invoice Line Items
Here's one method:
Invoices Table
On your Invoices
table create a calculation field Invoice Total
, which is the sum of all costs. The code for which is:
Sum ( Invoice Line Items::Cost )
Additionally on your Invoices
table create a calculation field Invoice Total Unpaid
, which is the cost if your Vendor Paid
field is not checked:
If (
IsEmpty ( Vendor Paid ) ; 0 ;
Invoice Total
)
Vendors Table
Now on your Vendors
table you can create your Cost Total
calculation field, the sum of all costs:
Sum ( Invoices::Invoice Total )
And a Cost Total Unpaid
calculation field, the sum of all unpaid costs:
Sum ( Invoices::Invoice Total Unpaid )