Calculations

Follow

The Calculation widget allows you to perform arithmetic (= + - / * ) operations on one or more previously entered Numeric question values in the form. The result of the arithmetic expression is stored in the calculation field.

In the example below, we have created a repeatable section for entering a list of parts used in a particular task. Each part has a Part Description, Quality and Unit Price. The calculation widget is used to calculate Quality x Unit Price for each part. We calculate the item price (= unit price x quantity) of every item entered into the repeatable section.

Sum and Count Operators

If your form contains a Repeatable Section container, you can use Sum and Count functions in your calculations to sum up all the values entered into a preceding repeated numeric field (e.g., to calculate a total or to count the number of times data was entered into a field for division of the total to calculate an average). Sum and Count operators can also be used with Table containers.

As an example, in the invoice above we can Sum the value of all the Item_Price calculations to get a subtotal.

 

We can then multiple the subtotal times a tax rate (a constant) to calculate the sales tax.

 

And finally add the Subtotal and Sales tax to get a Total Price.

 

If we want to get a count of the number of items ordered (i.e., number of Item_Price fields that were calculated), we can use the Count function which works the same way as the Sum function, but returns an integer count.

Parenthesis ( ) Group

In other circumstances you might consider using a parenthesis ( ) group to organize a complicated expression. If needed, you can nest parenthesis within parenthesis. The example below shows an alternative way to calculate the Total_Price without explicitly calculating a subtotal and tax as done above.

Use of Hidden Fields for Variables

In other circumstances you might consider using the “Hide in mobile app” property in numeric questions and calculations to store data values which you do not want displayed to the user. As an example, suppose you wanted to pass a tax rate to the form above. You could create a numeric field called “Tax_Rate”. By making the field hidden, it would not be explicitly displayed in the form, but could still be used in the tax calculation above. Hidden fields are also handy for very complex calculations that you want to do in parts.

Date:Time Calculations

The calculation widget can also be used with date:time values. The possible operations are: (1) subtract date:time1 from date:time2 to produce a difference in decimal-hours; or (2) add/subtract decimal-hours from date:time1 to produce a new date:time2. Be sure that you correctly set the “Kind” property to date:time if performing calculations that involve a date:time (even when the result will be a numeric value). When using the “Sum” operator to sum up a list of differences in decimal-hours, be sure to set the Kind to number, as these differences are stored as numbers.

Display time values can be formatted as hh:mm in the mobile app by using the “Display time values as hh:mm” property. Note however, that the actual values will be saved as decimal-hours.

Properties

Now, let's take a quick look at the right sidebar that contains the special properties you can use to control the look and behavior of calculations:

Caption text - Refers to the question caption as presented to the user. Think of this as the title for the question; it should be self descriptive. We recommend no more than three words for optimal display on mobile devices.

Hint - Additional help for the question will be displayed; short clear sentences work best. Use 80 characters or less for optimal display on mobile devices. The maximum number of characters is 500, including spaces. The following HTML formatting tags are currently recognized:

Android: <br>, <i>, <b>, <u>, <font color="xxx">, <H1>, <H2>, <H3>, <H4>, <H5>, <P>, <a>, <div>;
iOS: <br>;
PDF reports: <br>, <font color="xxx">.

Data name - Represents the name of the data that will be displayed in column headings. This property is automatically filled in based on the Caption Text but may be modified in the properties area. We recommend one or two word data names to keep column headings short. The maximum number of characters is 30. Spaces are not permitted in the Data Name field. 

Hide in website - Check this option if you wish to hide the widget in the View Data and Dispatch tabs of the website. 

Hide in mobile app - Check this option if you wish to make the widget invisible in the mobile app. You might want to do this so the mobile user cannot change the value, or if the value is being used in some intermediate calculation or logical expression.

Kind – Specifies the type of value used. For calculation widget, the kind of value can be Number or Date:Time.

Currency symbol – Places a currency symbol in front of the value. Note that these symbols are for display and PDF report purposes only. The currency symbol is not exported to Excel, CSV or other “Save as” formats. The currency is, however, exported via web services and Sync & Save.

Decimal place – Indicates how many decimal places should be displayed (not that the actual value is not rounded off).

Expression – Used to build the formula based on previously entered number values. Note that the calculation widget needs to be placed after any question fields that will be used in the calculation.

Advanced - Clicking on the Advanced arrow will reveal “Relevance conditions” and “Skip conditions” properties that can be used of further control the behavior of your form using sophisticated logical statements. Please refer to http://support.doforms.com/hc/en-us/articles/200446034-Using-Relevance-Skip-Logic for more information on these properties. 

Have more questions? Submit a request

Comments

Powered by Zendesk