Calculation fields can be used to write simple expressions to calculate values dynamically based on inputs given to other fields in your forms. This can be simple ‘total’ calculations or complex equations referencing other calculation fields and even data contained in repeatable sections.
Configuring a Calculation Field
When you build an expression using a calculated field, you have access to all of your form field values from within the expression builder tool for driving calculations. There’s an extensive library of searchable functions, most of which you’ll recognize if you’re familiar with building formulas in spreadsheets like Excel or Google Sheets. Also included are several functions that are Fulcrum data-specific, giving you the ability to include in your calculations your record’s status, latitude or longitude, and more.
Take a look at the following video for a deeper understanding of the Calculation Fields.
A few example use cases could be:
Calculation of dimensions, areas, and volumes for site surveys,
Determining totals for supply and inventory applications,
Weighting and averaging for dynamic scoring,
Displaying summary text with concatenation.
You can view all the available functions on our developer pages. Within the Code Editor, you will be able not only to have quick access to the available functions, you also have a list of available fields for you to use in the Calculations.
Take the gif below as an example. The idea is to obtain the area of a culvert based on the values entered in the width and length fields. All we have to do, is use the
SETRESULT function, and multiply those fields. The expression will look something like this:
Take a close look at the bottom of the Code Editor. Once you have added the fields you are using for your calculation, they will be available here to help you test your expression. Just type in sample values and verify the result that will appear on the left side of the values you entered.
You must select a format for displaying the expression result in the field options window.
There are four available format types:
Text - Use this for displaying text or unknown values.
Number - Use this only for displaying numeric values.
Date - Use this for displaying formatted date values. The value should be in the following format:
Currency - Use this for displaying formatted currency values. The value should be a number and you'll need to select a specific currency.
Having trouble writing your expression? Maybe some of these tips will help:
Code in a text field and
eval through a calculation field
This is a neat way to test expressions on a mobile device on-the-fly:
Add a calculation field to your app. Set the expression for this field to
INSPECT() function can be used to check the value being produced by any of the variables declared in your expression.
console.log() can be used to display values in the developer's console in the web browser while troubleshooting your code.
var area = ($culvert_length*$culvert_width);
var volume = area * $culvert_depth;
console.log('Culvert Volume = '+ volume);