Reader Review Form Calculations
  • 18 Mar 2024
  • 2 minute read
  • Dark
    Light
  • PDF

Reader Review Form Calculations

  • Dark
    Light
  • PDF

Article summary

Calculated fields may be created in a form using any number of form fields (variables) combined with standard mathematical operators. For example, a Total Rating field can be the sum of the Academic Rating and the Extracurricular Rating fields.

Add Fields that will Drive a Calculation

Ensure that each field is properly configured with an Export Key and a numerical Data type. 

  • Export Key - The export key should be all lowercase and should not include spaces. 

  • Data Type - The Int type indicates that the value in this field is a whole number. The Real type may be used for decimal values. Note: If another Data type is configured, submitted values will be concatenated in the calculation field.

Add a Form Field that will Perform the Calculation

Ensure that a text-based field is properly configured with an Export Key, a numerical Data Type, and a calculation formula.  This formula will add the value from the Academic Rating field and the value from the Extracurricular rating field. The sum will display as the value for this field. 

All standard mathematical operators are supported within the calculation formula setting including:

  • Multiplication (*)

  • Division (/)

  • Addition (+)

  • Subtraction (-)

  • Conditional Statements

In addition to standard mathematical functions, all JavaScript mathematical functions are also supported. For example:

Standard Mathematical Functions

 

Average

(@aca + @extra)/2

Multiple operators

((3*@aca) + @extra)/2 

Average with a consistent denominator

(@var1 + @var2 + var3) / 3

Average with a variable denominator If there are values in some but not all the variables in this formula, those will be averaged. There has to be a value in at least one of the variables. Otherwise, you'll get a divide-by-zero error; that's why variable 1 is assumed to be there (nothing conditional, just a literal 1 value), and only variables 2 and 3 will change the denominator based on if there's a value present or not.

(@var1 + @var2 + @var3) / (1 + ((@var2)?1:0) + ((@var3)?1:0))

Conditional Statements

 

Example 1

Check if the variable has a numeric value greater than 0, not just any value.

Place any valid calculation in the if-yes and if-no parts, but both must be present even if only to return nothing/an empty string.

(@variable > 0) ? (DO-THIS-IF-YES) : (DO-THIS-IF-NO) 

Example 2 

Check if there's a value in the variable (numeric or text, doesn't matter) and if yes, return a 1. If no return a 0.

 

@variable ? 1 : 0  

 

 Javascript Mathematical Functions 

 

Round up always 

Math.ceil((@aca + @extra)/2)

Round down always

Math.floor((@aca + @extra)/2)

Round

Math.round((@aca+ @extra)/2)

🔔 Important!

If a string value is being translated, append the export key in the calculation formula with "_text".

In these cases, use the following format for the calculation formula: translate("key", @export_text)

Click here for a comprehensive list of available JavaScript Math Library Functions.


Was this article helpful?