Skip to main content
How do Calculation fields work?

Creating powerful expressions in the calculation field.

Mike Meesseman avatar
Written by Mike Meesseman
Updated over a year ago

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.

Expressions

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.

Example

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:

SETRESULT($culvert_length*$culvert_width)

Process of setting up a simple expression to calculate the area of a culvert.

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.

For users wanting to calculate more complex results from their data, calculated field's code editor can leverage raw JavaScript. This means you can write complex functions (and entire programs) to return results out of user-entered data on-the-fly.

Display Formats

You must select a format for displaying the expression result in the field options window.

Format of a Calculated Field set to Number

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: YYYY-MM-DD.

  • Currency - Use this for displaying formatted currency values. The value should be a number and you'll need to select a specific currency.

Helpful Hints

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:

  1. Add a text field to your app. This is where you’ll enter JavaScript script.

  2. Add a calculation field to your app. Set the expression for this field to eval($code_field_data_name)

  3. Sync your mobile device, and now you can code using JavaScript into the text field. You’ll see the result work in the eval field! 

INSPECT()

The INSPECT() function can be used to check the value being produced by any of the variables declared in your expression.

Console.log()

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);

SETRESULT(volume);

console.log results displayed on the browser's console.

console.log() will need to be removed once you have completed troubleshooting. Failure to remove the console.log() from your code will result in issues on the Fulcrum mobile apps.


Did this answer your question?