Calculation questions

The calculation question type in a form is a special mathematical question type that allows the device user to perform a calculation in a form or you to construct an expression whose result can be evaluated in a form report.

Calculation questions can reference custom variables, as well as the answers to text and numeric question types. Calculations also support the most common mathematical expressions.

Restriction: Calculation questions are not available in dynamic or static question table groups.

On the device, an expression in a calculation question on a form is a read-only text box. In order to answer the calculation question, the user taps the equals button. The result of the calculation is then stored against the question in the database and can be used in forms analysis or Business Intelligence.

When creating a calculation question in a form, you can construct simple or complex calculation expressions. Field View supports the following operators:
  • Numbers
  • Decimals
  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Square root
  • `
  • Equals
  • Not equals
  • Greater than
  • Less than
  • Bracketing
  • If-then-else, including commas

You can also add text, and pull values from both simple and complex custom variables, as well as from answers to other questions in the form. You can also construct calculation questions using text comparisons and conditional statements.

Table 1. Examples of how expressions can be used in calculation questions
Expression Meaning
10 + 10 Addition of two numbers. The result is 20
(100/10) * 20 Division and multiplication. The result is 200
100-98 Subtraction. The result is 2
√961 Square root of 961. The result is 31
(Q1 + Q2 + Q3 + Q4) / 4 The answers to numeric questions 1, 2, 3, and 4, added together, and then divided by 4 to get an average
If(Q(How much CO2 has the project used) < CV(Project CO2 Limit), 'CO2 Usage is OK', 'The CO2 Limit has been exceeded') If the answer to the question "How much CO2 has the project used" is less than the value of the simple custom variable "Project CO2 Limit", then the result of this calculation question is text reading "CO2 Usage is OK; else, the result is "The CO2 Limit has been exceeded"
If(Q20 = 'N/A', 0, Q20) If the answer to question 20 is "N/A", then the result of this calculation question is zero (0); else, the result of this calculation question is the value that the user entered for question 20
If(Q15 = 'N/A', 0, Q15) + If(Q16 = 'N/A', 0, Q16) Assume questions 15 and 16 are numeric question types.

If the answer to question 15 is "N/A", then replace that with zero (0); else, use the numeric value that the user entered for question 15. If the answer to question 16 is "N/A", then replace that with zero (0); else, use the numeric value that the user entered for question 16.

The result of this calculation question is the sum of those two values.

CV(CO2 Vehicle Emissions,Q7.What vehicle are you driving?,Q8.What fuel is your vehicle using?) Assume that there are two questions in the form that have predefined answers:
  • Q7.What vehicle are you driving? Predefined answers: Auto, Van, Truck
  • Q8.What fuel is your vehicle using? Predefined answers: Propane, Diesel, Gasoline
Assume that the business unit or project has a complex custom variable called "CO2 Vehicle Emissions":
  • The top row of this variable is Vehicle Type
  • The first column of this variable is Fuel Type
  • Each cell in the rest of the table contains a value for the combination of Vehicle Type/Fuel Type
Assume you are creating a calculation question called "CO2 Rating" using the complex custom variable "CO2 Vehicle Emissions". In the custom variable lookup:
  • The CO2 Vehicle Emissions custom variable is selected
  • The row lookup is question Q8.What vehicle are you driving?
  • The column question is Q7.What fuel is your vehicle using?

The result of this CO2 Rating calculation question is the value that is derived from the custom variable based on the combination of vehicle type and fuel type that the device user selected in questions 7 and 8.

A calculation question expression is validated while you are constructing it. If the expression is invalid, the calculation question cannot be saved.