Calculations on data entered in a form

Calculations on data entered in a form

Requirement

Values entered in a form for a US Gallons field are used to calculate the corresponding value in UK Gallons. Similarly, values entered in a Miles field are used to calculate the corresponding values in kilometers.

Use Case

When a vehicle/fleet management system is used across multiple countries, the measuring units vary a lot. This system contains a Vehicle form, which holds the details of the vehicles in the business, and Vehicle Usage Stats form, which handles the travel and fuel consumption details of a vehicle. When showing stats like fuel consumption or distance traveled, there may be a need to show the data in both US and Imperial systems to better understand the volume of resources used.

See how it works

Steps to follow

1. Create two forms with the following details:
Form
Form Link Name
Field Type
Field Name
Field Link Name
Vehicle
Vehicle
Single Line
Vehicle Name
Vehicle_Name
Drop Down
Fuel Type
Fuel_Type
Number
Registration Number
Registration_Number
Vehicle Usage Stats
Vehicle_Usage_Stats
Lookup (Vehicle)
Vehicle Name
Vehicle
Date
Date of Travel
Date
Decimal
Fuel (in US Gallons)
Fuel_in_US_Gallons
Decimal
Distance (in miles)
Distance_in_miles

2. Add a formula field in the Vehicle Usage Stats form with the below expression. Rename this formula field to Fuel (in UK Gallons).
  1. //Taking the value in the Fuel(in US Gallons) field, we are converting it to UK Gallons by dividing the former with 1.201
  2. input.Fuel_in_US_Gallons / 1.201

When the fuel consumption is added or updated, the values will get recalculated.

3. In the same way, add a formula field in the Vehicle Usage Stats form and add the below expression to it. Rename this formula field to Distance (in Kilometers).
  1. //Convert miles to kilometers by multiplying miles value with 1.609
  2. input.Distance_in_Miles * 1.609

4. Check the Make field visible in the form checkbox in the Field Properties of both Formula fields to see the values on the form.

See how it works

 

Points to Note

  • The values from the formula field can also be rounded to two decimal places using the expression below: 
  1. round(input.Fuel_in_US_Gallons / 1.201,2)