The Calculation tool allows the mobile user to perform arithmetic operations on one or more previously entered fields in a form. doForms provides three different types of calculations: Numeric, Text, and Date/Time.
Numeric calculation: Performs basic arithmetic calculations (addition, subtraction, multiplication, and division) between one or more fields to display a numeric result in another field. You may also create a numeric calculation using Date/Time fields (i.e., adding or subtracting day numbers of the month or month numbers).
Text calculation: Joins together multiple text fields and displays the result in another field. For example, you may wish to combine a "First name" field and a "Last name" field into one field called "Full Name." You may also include Mobile User IDs, Nicknames, Constants (text strings), and spaces in text calculations. In addition, you can also use a text calculation as an input source to launch Google Maps from a form. Finally, you may also create a text calculation using the day name (e.g., Monday), month name (e.g., July), or year (e.g., 2017) of Date/Time fields.
Date/Time calculation: Adds or subtracts dates and times to display either: 1. A value in decimal hours, or 2. A new date/time, in another field. This option can be very useful for recording employee work hours.
A numeric calculation 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 container for entering a list of parts used in a particular task. Each part has a description, unit price, and quantity. The Calculation tool will be used to create a numeric expression that multiplies unit price by quantity to yield an extended price:
(Unit price) * (Quantity) = (Extended price)
To begin the process, we inserted the repeatable container tool (with caption Item), and then inserted into it a Text tool (with caption Description), and two Numeric tools (with captions Unit Price and Quantity). These are highlighted in red, below.
We then moved a Calculations tool into the repeatable container, and entered a caption of Extended Price (highlighted in green, below). We also assigned it a dollar sign ($) Currency symbol, and entered a value of two (2) Decimal places.
Now we need to enter the Expression parameters for the Extended price calculation:
The Operator drop-down is the equals sign (=).
From the Field drop-down, select the Unit price field (highlighted in red, below), and then click the Add expression link (highlighted in green, below):
A new Operator drop-down and Field drop-down will appear (highlighted in red, below). Select the multiplication sign (*) from the Operator drop-down, and then select the Quantity field from the Field drop-down.
This final expression:
= Unit price * Quantity
yields a value that will be displayed in the Extended price field. In the example below, the mobile form user has entered a Unit price of $9.00, and a Quantity of 10. The doForms form has performed the calculation and entered the value of $90.00 in the Extended price field.
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, 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.
Power Operator (^)
The power operator allows you to set a value in the form to the power of a constant or another value in the form. For exmaple, you would use the power operator to solve the follow equation: x = (b+ (b^2-4ac)1/2)/2a
Parentheses Group ( )
In other circumstances you might consider using a parentheses group ( ) to organize a complicated expression. If needed, you can nest parentheses within parentheses. The example below shows an alternative way to calculate the Total_Price without explicitly calculating a subtotal and tax.
Use of Hidden Fields for Variables
In other circumstances you might consider using the Hide (Mobile) setting (see info below) 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. Hidden fields are also handy for very complex calculations that you want to do in parts.
A text calculation joins together multiple text fields and displays these fields within another field. For example, you may wish to combine a "First name" field and a "Last name" field into one field called "Full Name." You can also use a text calculation as an input source to launch Google Maps from a form.
The following text calculation joins together four fields, Address, City, State, and Zip code, into one field called Full address.
In addition to text fields, you may choose to use Mobile User IDs, Nicknames, Constants (text strings), and spaces in text calculations. The following image shows available fields for use in text calculations:
Note that you may choose to use a text calculation as an input source to launch Google Maps from a form. Using our example from above, we have already created a text calculation called Full address. Insert a Google Maps action button into the form, and reference the Full address field as its Relevant question. Fill in the other settings for the action button using the image below as an example:
The calculation tool 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/Time to produce a new Date/Time.
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-hour
When using the Sum operator to sum up a list of differences in decimal-hours, be sure to set Calculation Type to Numeric, as these differences are stored as numbers.
Caption text: The caption is used in most cases to ask the question. In others it may be a column heading. This is a required field. Please keep in mind that captions will wrap when form elements do not fit within the width of the screen. It is important to consider how your captions will be displayed. Captions on a larger screen might look perfect, but on a smaller device, they may be forced to wrap several times. In this situation, a smaller caption should be used.
Hint: Provides additional information to the mobile form user on how a question (i.e., Caption text) should be answered. The Hint font size is smaller than the Caption font size.
Additional HTML styling can be applied on hints and captions.
Data name: Because this is a required field, doForms will default the Data name to match the Caption or Label. If these are blank, doForms will generate a generic Data name name with a sequential number (such as "untitled10"). Since it is used throughout the system, it is recommended that you enter a descriptive Data name that is easily identifiable. Nondescript Data names are difficult to find and select at a later time (e.g., when performing a calculation).
Calculation Type: Specifies the type of calculation created: Numeric, Text, or Date/Time.
Use Currency Symbol: For numeric calculations only, this setting 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.
Negative Number These settings determine what the answer looks like if the numeric entered is negative. If "Red Text" is selected it will turn the answer red and if "Bracket" is selected it will put the negative number into () brackets. Both settings can be applied or the user can select one.
Decimal Place: For numeric calculations only, this setting indicates how many decimal places should be displayed (note that the actual value is not rounded off).
Show text as string on mobile: For text calculations only, this setting removes the text calculation field name (as well as borders) from the mobile form.
Display time values as hh:mm: For Date/Time calculations only, this setting formats time values as hh:mm in the mobile form. Note, however, that the actual values will be saved as decimal-hours.
Expression: Used to build the formula based on previously entered number values. Note that the calculation tool needs to be placed after any question fields that will be used in the calculation.
Appearance: doForms allows you to set a default set of appearance parameters. This eliminates the need for you to have to set colors and other parameters each time you add an element to your form. You can however override the default settings for any tool by simply picking the Custom option. You can also edit the default by clicking on the edit defaults option.
Justification: Allows you to apply text justification settings to certain elements of the tool. Choose the appropriate radio button for the Caption, Hint, and/or Answer fields as follows:
L: Left-justifies the text.
C: Center-justifies the text.
R: Right-justifies the text.
Remove Space: This parameter is used to remove the space just before and just after the tool. By removing space two elements can be made to appear linked or as a single element.
Hide - These settings allow you to hide the form field from users in specific situations. The settings are as follows:
View data edit: Hides this field from a web portal user when editing a submitted form through the 'View data' tab.
View data new: Hides this field from a web portal user when creating a new form through the 'View data' tab.
Dispatch edit: Hides this field from a web portal user when editing a submitted form through the 'Dispatch' tab.
Dispatch new: Hides this field from a web portal user when creating a new dispatch through the 'Dispatch' tab.
Mobile: Hides this field from a mobile user when filling out a form.
Web App: Hides this field from a web app user when filling out a form.
In PDF and Print: Hides this field when the form is converted to PDF or printed.
Form Links: Hides this field on forms that are sent as form links.
Only display this question if: This is a very powerful option as it allows you to hide form elements, only exposing them if the answer to a question in your form meets the criteria you have set. Being able to hide fields unless they are needed makes form more user friendly. For example, if you have a Choose One question with the answers Yes and No, then you can say "Only display this form element if" the answer to the Choose One is "equal" to "Yes." You can combine criteria with other criteria, thus creating complex criteria for showing/hiding form elements.
Jump to if : This setting works the same as jump to except only triggers when a condition is met. For example, a user could set their form to jump to "Customer Name" if question "Add New Customer?" was equal to yes.