Previous Next

In the form designer, click + Add hidden field, then choose calculate as the field type. You will be able to use a wizard to construct common calculation expressions, or edit the expression by hand for more complex or expert use.

calculate: calculate using prior field values. The value of this field will be calculated using the expression in the calculation column (e.g., "(${age1}+${age2}+${age3}) div 3" to calculate an average age from three prior age fields). This is an automatic, hidden field type: it is filled in automatically and never shows up in the survey's user interface.

The easiest way to build a calculation expression for spreadsheet form definitions is to use the calculation-builder on the server's Design tab: for any new or existing form, select Tools, then Build calculation.

For hand-creating or hand-editing calculation expressions, see the Using expressions in your forms help topic.

In the spreadsheet form definition:

typenamecalculation
calculatefieldnameexpression

Advanced fixed-location calculations

In the form designer, click + Add hidden field, then choose calculate_here as the field type. You will be able to use a wizard to construct common calculation expressions, or edit the expression by hand for more complex or expert use.

calculate_here: same as calculate (immediately above), but calculate_here calculations only happen when users reach the field's place in the survey. (In contrast, regular calculate fields calculate whenever forms load or save, and whenever fields upon which they rely change.)

You rarely want to use calculate_here
Please note that the two examples below may be the only legitimate uses of calculate_here fields. The vast majority of your calculations should be in regular calculate fields. This is because regular calculate fields automatically re-calculate when needed, which is almost always a good thing.

For one example where calculate_here is useful, consider the case where you want to capture the number of seconds already spent filling or editing the form at the precise moment that the user first reaches a particular point: for this, you can use a calculate_here field at that point, with "once(duration())" in its calculation column. Or, to capture the date and time at which the user first reaches a particular point in your form, use a calculate_here field at that point, with "once(format-date-time(now(), '%Y-%b-%e %H:%M:%S'))" in its calculation column. For more on these and other expressions, see the help topic on Using expressions in your forms.

In the spreadsheet form definition:

typenamecalculation
calculate_herefieldnameexpression

Previous Next