Add, subtract, multiply, and divide values

Microsoft Office InfoPath

Show All Show All

Add, subtract, multiply, and divide values

You can use expression boxes to add, subtract, multiply, and divide values, as well as perform other calculations. When you create formulas in an expression box, you refer to the fields and groups to which controls on the form are bound, rather than the controls themselves. The formulas are created using XPath, but you can follow these steps without knowing XPath.

  1. In design mode, place the insertion point where you want to insert the expression box.
  2. If the Controls task pane is not visible, click More Controls on the Insert menu.
  3. In the Controls task pane, click Expression Box.
  4. To add, subtract, multiply, or divide values in two fields, enter an expression such as one of the following in the XPath box in the Insert Expression Box dialog box.
    Expression typeExpression
    Add two fieldsmy:field1 + my:field2
    Subtract a field from another fieldmy:field1 - my:field2
    Multiply two fieldsmy:field1 * my:field2
    Divide a field by another fieldmy:field1 div my:field2

    Note  In the preceding table, my:field1 and my:field2 are only examples. When you type your expression, you must use an XPath expression that identifies your specific fields.

    ShowHow?

  5. To test the formula, click Preview Form on the Standard toolbar.

Note  If an empty field is included in a formula that adds, subtracts, divides, or multiplies, the expression box will show the total as NaN or 1. #QNAN (Not a Number). To avoid this, you can create a default value for the fields used in the equation.