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.

What Relationship Must Be Established to Get Totals from Two Tables?

Featured Replies

  • Newbies

I have the following:

 

Table 1 – Expenses

 

Field A: Date

Field B: Concept

Field C: Amount

 

Table 2 – Flight Time

 

Field D: Date

Field E: Flight Time (in hours)

 

I need a report that will give me the expense cost per hour, i.e. the total of Field C divided by the total of Field E.

 

Table 1 and Table 2 are not related. What relationship must I establish between them to obtain my desired result?

 

If establishing a relationship between the tables is not the answer, how else can I achieve the figure I need?

 

Thank you for any help that can be provided. 

Are the tables related to the same parent table? I would think that each has a foreign key. Otherwise, I'm not sure that I understand what you're doing.

If no relationship, you could always calculate using ExecuteSQL.

Can you describe this use case in a paragraph?

  • Author
  • Newbies

bcooney,

 

Thank you for your response.

The tables are not related in any way.

In table 1 I have records like:

01/01/17 Fuel $10

03/17/17 Catering $11

06/09/17 Repairs $12

In table 2 I have records like

02/02/17 1.5 hours

08/05/17 2.2 hours

I need a layout in which I can include the following calculation:

10 + 11 + 12 = $33 divided by 1.5 + 2.2 = 3.7 for a total of 33/3.7 = $8.92

Imagine you have many of the first type and second types of records. You always want a single total referencing all records? Isn't there a Flight ID in common?

Are you really using FM11?

If not, here's a demo showing how I might use sql to do this.

demo.fmp12.zip

  • Author
  • Newbies

bcooney,

Yes to your question about many records in table 1 and many in table 2.

I need a single total referencing all records but by year, i.e. some of the records in table 1 and table 2 belong to different years. 

No flight ID or any other field in common.

Yes, I am using FMP 11. 

 

Sorry, I can't think in fm11 anymore. 

You could create a Year table, with a record for each year. With a start and end date in the Year table, you could make a relationship to the date fields in the other tables. Then your calculation in the Year table would look like:

Round( Sum( Expenses::Amount ) / Sum( Flight Time::Flight Time ) ; 2 )

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.