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.

Conditional Calculation based on fields from another table

Featured Replies

Hello everyone,

I've got a problem. I'm trying to build up a very simple database with two tables. Basically I want one set of records where I can input the repayments of some loans, and another table where I can get the status of the loans (how much is left to pay and how many rates have been paid so far or how many rates are left)

TABLE 1 FIELDS (Multiple Records)

CREDITOR, Text Field, (has a dropdown with 3 names)
DATE, Date Field
AMOUNT, Number Field

TABLE 2 FIELDS (One Record)

CREDITOR1, Calculation Field = 10.000 - If (TABLE1::CREDITOR = "CREDITOR1" ; TABLE1::AMOUNT ; 0)
CREDITOR2, Calculation Field = 20.000 - If (TABLE1::CREDITOR = "CREDITOR2" ; TABLE1::AMOUNT ; 0)
CREDITOR3, Calculation Field = 30.000 - If (TABLE1::CREDITOR = "CREDITOR3" ; TABLE1::AMOUNT ; 0)

Of course there is a mistake in my calculation since it doesn't work as intended. I've tried adding a relationship between the two tables with corresponding fields for the IF function (Creditor from Table1 = Creditor from Table2 and Amount from Table1 = Amount from Table 2).

Is it a silly mistake or I took the wrong approach altogether?

 

 

Can you explain what are you trying accomplish by this? Usually, when you have two tables, it is to implement a one-to-many relationship. For example, one loan has many payments - so there would be multiple records in a Payments table for each record in the Loans table, and the two tables would be related by LoanID.

I cannot figure out what your two tables represent in real life and what exactly are you trying to calculate.

 

  • Author
14 minutes ago, comment said:

Can you explain what are you trying accomplish by this? Usually, when you have two tables, it is to implement a one-to-many relationship. For example, one loan has many payments - so there would be multiple records in a Payments table for each record in the Loans table, and the two tables would be related by LoanID.

I cannot figure out what your two tables represent in real life and what exactly are you trying to calculate.

 

I'll try to further explain my issue. On Table 1 I have a set of records which contains data such as:

Creditor: Creditor1
Amount is 1000

Creditor: Creditor1
Amount is 2000

Creditor: Creditor2
Amount is 500

On Table 2 I want a single record where to perform some calculations such as:

Total Debt 1 is 10000
Total Debt 2 is 5000

Calculation field which calculates:

Total Debt 1 - All the Amounts found in records of Table 1 where Creditor is Creditor1
Total Debt 2 - All the Amounts found in records of Table 1 where Creditor is Creditor2

26 minutes ago, n7mafia said:

On Table 2 I want a single record where to perform some calculations such as:
...
Total Debt 1 - All the Amounts found in records of Table 1 where Creditor is Creditor1
Total Debt 2 - All the Amounts found in records of Table 1 where Creditor is Creditor2

That is not a good thing to ask for. You would have to add a new calculation field to this table whenever you add a new creditor. That's not how a database is supposed to work. Not to mention how difficult this would be to implement (and how slow it would probably be).

There are number of ways to get an overview of total debt by creditor:

  • You can produce a summary report of the Loans table (your "Table 1"), summarized by creditor and using a summary field to show the total debt amounts;
  • You can (and very likely should) add a table of Creditors, add a calculation field to sum the related amounts from Loans, and view the results in List or Table view of this table;
  • Use the ExecuteSQL() function to produce the summary as text (this would be more suitable for a scripted overview, because using the function in a calculation field can be very slow).

 

 

 

 

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

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.