Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

calculation from relationship involving multiple tables

Featured Replies

I'm stuck on a problem that seems like there should be an easy answer, but I can't seem to get the answer on my own (and didn't find anything searching the forum).

The relevant tables and keys look like this:

-----

Project Table:

ProjectID

ContactID

TotalPaidToContactForProject

-----

Payment Table:

ContactID

-----

PaymentLine Table:

ProjectID

AmountPaid

I simply want a calculation field in the Project table that calculates the total amount paid to a contact on a particular project (we'll call it TotalPaidToContactForProject) that aggregates/sums the AmountPaid field from PaymentLine based on a combination key relationship of both ContactID (in the Payment table) and ProjectID (in the PaymentLine table). Keep in mind that the ContactID is set in the Payment table, but the payment might include multiple projects, so the project ID is set in the PaymentLine table. Hence my conundrum.

Assume for this example that other elements such as the Contact table and certain connecting key fields exist as they should (i.e. PaymentID field linking Payment and PaymentLine tables).

My failed solution was to try creating a ContactID calc field in PaymentLine to pull over the ContactID from the Payment table, but since it can't be indexed it will not work for summing from the Project table.

Any help would be appreciated!

a ContactID calc field in PaymentLine to pull over the ContactID from the Payment table

Indexing aside for a moment: how would you do this - when Payment and PaymentLine have no common fields?

The way you describe it, PaymentLine records are related to a specific project, and a project is related to ONE contact only - therefore ALL PaymentLine amounts have been paid to the owner of the parent project.

Edited by Guest

  • Author

I left out certain given fields and data to keep things simple and focus on the tables and fields in question. Go ahead and assume there is a Contact table and also that the Payment and PaymentLine tables are related by a PaymentID key field. Sorry for any confusion.

OK, so if I am not utterly confused yet, you have something like:

Contacts -< Projects -< PaymentLines >- Payments >- [Contacts]

If so, TotalPaidToContactForProject (in Projects) should be =

Sum ( PaymentLines::Amount )

There is no need for a ContactID in PaymentLines, since there is a ProjectID - and the project can belong to only one contact. IOW, the total amount paid to a contact on a particular project is the total amount paid on a particular project - unless I am still missing something...

  • Author

Yes, you are correct. I was over-complicating it because of an ERD oversight. Thank you for your help!

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.