PROBLEM
In ArcGIS Survey123 Connect, formulas are used to perform calculations between several inputs to calculate the total value. When the total value field is set to read-only and the calculation column of the total value is specified, specifying all input fields calculates the total value automatically. For example, calculating the total cost of a construction work (total value) based on the price of tiles, pipes, cements, and manpower (input), or determining the population estimate of wildlife in a sanctuary (total value) based on the observation of multiple animal species (input). However, when one of the inputs is left blank, the total value is not calculated.
The image below shows the read-only total value field (Total cost) configured to calculate the sum of several inputs (Admin cost, Finance cost, Legal cost, and Insurance) in the ArcGIS Survey123 Connect XLSForm.
The image below shows the ArcGIS Survey123 web form where the total value field (Total cost) is not calculated when one of the inputs (Insurance) is blank.
A blank field is considered a null value. ArcGIS Survey123 does not identify null values in a calculation, so the total value field is not calculated when the input field is blank.
Follow the steps below to create a read-only field that calculates the total value automatically even if the input field is left blank or unanswered.
Set a condition to assume the blank field equals to zero
The total value field is calculated by setting input fields with the 'If' condition. The condition is specified to assume the value of the blank field is zero.
Note: Hidden question types are considered as text fields by Survey123 by default, however, users have the option to specify a different field type for hidden questions.
if(${decimal_fieldname}>0, ${decimal_fieldname}, 0)
Note: If a condition is set in the decimal or integer field instead of the hidden field, the error message, "Error converting XLSForm" is returned.
round(number(${hidden_fieldname1}) + number(${hidden_fieldname2}) + number(${hidden_fieldname3}) + ..., number of decimal places)
The image below shows the ArcGIS Survey123 Connect XLSForm configured with conditions and the calculation of the total value.
The image below shows the ArcGIS Survey123 web form. Although one of the inputs (Insurance) is blank, the total value (Total cost) is calculated.
Set the default value as zero
By setting the default value to zero, any input field that is unanswered is calculated as zero instead of left blank and stored as a null value.
Note: The drawbacks of this method are: • Unless a value is specified in the input field, the number zero always displays on-screen. • The zero value in the input field must be erased manually before a value can be specified. • If a user specifies a value in the input field and later decides to leave the field with no specific answer, the user must insert the number zero manually after deleting the input value specified. Failure to do so causes the field to be considered null, and the total value field cannot be calculated.
round(${decimal_fieldname1} + ${decimal_fieldname2} + ${decimal_fieldname3} + ..., number of decimal places)
The image below shows the ArcGIS Survey123 Connect XLSForm configured with the default value, and the calculation of the total value.
The image below shows the ArcGIS Survey123 web form. Since the default value is set to zero, the total value field is still calculated although one of the input fields is unanswered.
Get help from ArcGIS experts
Download the Esri Support App