The **Calculation** tool allows the mobile user to perform operations on one or more previously entered fields in a form. doForms provides three different types of calculations: Numeric, Text, and Date/Time. Calculations can also be used to set fields equal to other fields. This will allow you to put the customer name on every page of your form. You can also set calculations equal to User Variables or Account Variables. You can set a User Variable up requiring the mobile user to enter their employee ID the next time they use doForms. The value is stored on their device and the calculation field will automatically be replaced with the employee ID each time the form is opened.

**Numeric****calculations**: Performs basic arithmetic calculations (addition, subtraction, multiplication, and division) between one or more fields to display a numeric result. You can also use the calculation tool to set the field equal to date parts like day of the month or month number. IF you create user variables you can specify a numeric variable. You will see this variable in your field pick list. Their is a tax rate account variable. You can use this variable in calculations when building invoices. Then if you change the tax rate variable all of your forms will automatically use the new tax rate. You can create and manage variables in the manage section.**Text calculations**: You can either combine fields into a single string or just use this calculation to set a field equal to another field or a user or account variable. You can set the field equal to date parts like day of the week. You can also set the field equal to your mobile users name or Mobile ID. Text calculations allow you to also numeric fields. Create a string that says I sold 10 apples. Where 10 is from the numeric field number sold.**Date/Time calculations**: Add or subtract dates and times to display either: 1. a value in decimal hours, or 2. a value using the HH:MM:SS fomat. This option can be very useful for recording employee work hours.

# Operations

## Numeric calculations

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.

### 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.

## Text Calculation

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:

## Date/Time Calculation

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.

# Properties

**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.