# How on a Form to Do Calculations Involving Fields from Multiple Related Tables?

**URL:** <https://www.five.org/t/how-on-a-form-to-do-calculations-involving-fields-from-multiple-related-tables/435>\
**Category:** How do I?\
**Tags:** how-to\
**Created:** [July 27, 2024, 6:58pm UTC](https://www.five.org/t/how-on-a-form-to-do-calculations-involving-fields-from-multiple-related-tables/435 "2024-07-27T18:58:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vladt](https://avatars.discourse-cdn.com/v4/letter/v/b5ac83/32.png) [@vladt](https://www.five.org/u/vladt)\
**Post date:** [July 27, 2024, 6:58pm UTC](https://www.five.org/t/how-on-a-form-to-do-calculations-involving-fields-from-multiple-related-tables/435/1 "2024-07-27T18:58:12Z")

</div>

Hello Support,

I have two related tables – Table A and Table B.  
Table A has two fields – Field 1 and Field 2.  
Table B also has two fields – Field 10 and Field 20.  
I have a Form sourced from Table A. The Field 2 fields of Table A on the Form has to be calculated by formula: Field 2 = (Field 1 \* Field 10) / Field 20.

How to do it on the Form step-by-step?

I believe many people would be happy to know the answer to this question.

THANK YOU!

Vlad T.

---

<div class="post-metadata">

**Author:** ![Pranoy](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/pranoy/32/281_2.png) [@Pranoy](https://www.five.org/u/Pranoy)\
**Post date:** [July 29, 2024, 12:48am UTC](https://www.five.org/t/how-on-a-form-to-do-calculations-involving-fields-from-multiple-related-tables/435/2 "2024-07-29T00:48:53Z")

</div>

Hi @vladt

To assist you better, I need more details about your database and the structure of your forms within your app. If you could export and send me the FDF of your application, that would help me in getting a better idea. You can send the FDF here or email it to me at [pranoy@five.co](mailto:pranoy@five.co).

Here is a link to our documentation that can help you export the FDF: [Exporting and Importing FDF](https://help.five.org/2.6/docs/applications/export-import-fdf/).

---

<div class="post-metadata">

**Author:** ![RileyAnderssen](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@RileyAnderssen](https://www.five.org/u/RileyAnderssen)\
**Post date:** [July 29, 2024, 5:20am UTC](https://www.five.org/t/how-on-a-form-to-do-calculations-involving-fields-from-multiple-related-tables/435/3 "2024-07-29T05:20:45Z")

</div>

Hello Vladt,

Attached is an FDF containing the set up you have described as well as the functionality to produce the calculation you are requesting. To do this calculation, you must use an SQL query and a JavaScript function.

The process is essentially as follows  
**1. In form A, select the record from table B to be used for the calculation.**  
 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/1X/031daa925dbf6cdac7912e4a8f79fd4232c93db2.png)

The above image contains the SQL query used to retrieve the required values from Table B for the calculation to be made using the record selected within form A.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/1X/85a004a4c070a7b0931ebf70b9be7818b90f6faf.png)  
 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/1X/1190079b6ebc1076cb718e2ddb416755828d2636.png)

This SQL query is attached to the ‘Table B Key’ field with form A, allowing it to use the value select within this field to complete the query.

**2. In form A, input the value to be used in the calculation (Field 1)**

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/1X/d71e678b059eb498a5ba28f06d83ca489d39e358.png)

This field has a JavaScript function attached to the ‘OnExit’ event.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/1X/30f39314d64f47faa3030dcb7b44258027dae828.png)

This JavaScript function makes the calculation after a value has been entered into ‘Field1’ on Form A.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/1X/79b0365e82ba6ecdd5f8d19c3ccbe753570a8eae.png)

It uses the getMetadata function on the Five object in conjunction with the previously attached SQL query to acquire the values from table B. For information regarding the syntax of the getMetadata function, refer to [getMetadata() | Five | Low-Code For Real Developers](https://help.five.org/2.7/docs/api/five/functions/get-metadata/)

**Step 3. After entering the value to be used in the calculation within Form A (field 1), click out of the text box and Field 2 will be filled with the result of the cal**culation.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/1X/ba88787987c5a04563db8a1db512614684644bcc.png)

**Note** : Since you are currently using a free trial, you will only be able to have one application within the cloud version at a time, however, you can have multiple within the local version. The location version can be downloaded via [Download | Five](https://five.co/download-five/)

Feel free to ask any questions, more than happy to provide further information,  
Riley.  
[CalculatedFields-20240729-050721212736278.fdf](https://www.five.org/uploads/short-url/dDndCTDYe2jninxVkEXbqX4SUtH.fdf) (3.4 MB)

---

<div class="post-metadata">

**Author:** ![vladt](https://avatars.discourse-cdn.com/v4/letter/v/b5ac83/32.png) [@vladt](https://www.five.org/u/vladt)\
**Post date:** [August 1, 2024, 12:25am UTC](https://www.five.org/t/how-on-a-form-to-do-calculations-involving-fields-from-multiple-related-tables/435/4 "2024-08-01T00:25:30Z")

</div>

Hi Riley,

Thank you for the detailed reply. I downloaded the .fdf file you provided and imported it to the standalone version of FIVE. Unfortunately, when I tried to run the app, it gave me an error (see screenshots attached).

Nevertheless, I’ll try to replicate the method you described and will let you know how it goes.

Regards,

Vlad T.

 ![Screenshot 2024-07-31 200336](https://canada1.discourse-cdn.com/flex030/uploads/five/original/1X/f5d144261ab56ec7c7e5c38f5418fd6787a139b7.jpeg)  
 ![Screenshot 2024-07-31 200418](https://canada1.discourse-cdn.com/flex030/uploads/five/original/1X/eaa7af4db86202efaf42f9966418a5ac0f1748a7.jpeg)

---

<div class="post-metadata">

**Author:** ![RileyAnderssen](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@RileyAnderssen](https://www.five.org/u/RileyAnderssen)\
**Post date:** [August 1, 2024, 12:48am UTC](https://www.five.org/t/how-on-a-form-to-do-calculations-involving-fields-from-multiple-related-tables/435/5 "2024-08-01T00:48:33Z")

</div>

Hello Vladt,

I did the sample app in our upcoming release, 2.7. The version you are currently using is 2.6. We have had a change where on a form field in 2.6, you have a switch to include a field in the list, in 2.7, we have changed this to a conditional field.

All you need to do is go into (using the same structure in the fdf I sent):  
Visual \> Forms \> Click TableAs \> Pages \> General \> Fields \> Field1 \> Adjust the switch under ‘Include in list’ \> repeat for TableAs Field 2, TableBs Field10, and TableBs Field 20.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/1X/c54552135264e35acbbc4494830306db620f691d.png)

The image above displays the switch.

Let me know if you need any extra help, can provide a more detailed walkthrough if needed!

Thanks,  
Riley.

---

<div class="post-metadata">

**Author:** ![vladt](https://avatars.discourse-cdn.com/v4/letter/v/b5ac83/32.png) [@vladt](https://www.five.org/u/vladt)\
**Post date:** [August 1, 2024, 3:13am UTC](https://www.five.org/t/how-on-a-form-to-do-calculations-involving-fields-from-multiple-related-tables/435/6 "2024-08-01T03:13:55Z")

</div>

Thanks for the heads-up, Riley! When will the new release be available for download and what else is new in it (if you may say)?

---

<div class="post-metadata">

**Author:** ![Dom\_Five.Co](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/dom_five.co/32/38_2.png) [@Dom\_Five.Co](https://www.five.org/u/Dom_Five.Co)\
**Post date:** [August 1, 2024, 3:52am UTC](https://www.five.org/t/how-on-a-form-to-do-calculations-involving-fields-from-multiple-related-tables/435/7 "2024-08-01T03:52:16Z")

</div>

Hi Vlad, it shouldn’t take too much longer for our new release to come out. We will publish a feature overview on our website and we’ll make sure to give it to you when it’s ready! 🙂
