How to calculate running total

We are going to calculate a running total on each line of a purchase order template. We will achieve this by applying a Var tagging element, thus creating a variable, which value we will increase on each line with the line amount from the current data context (line record).

The end result will look like this:

Step 1: Create a variable before the List tagging element

  1. Insert the Var tagging element before the List tagging element.
  2. Set initial value of this variable.
  3. Give a name to this variable.

Step 2: Increase the value of the variable on every line iteration

  1. Insert the Var tagging element somewhere within the List tagging element. Make sure you are not in the context of some other Field tagging element.
  2. Give the same name to this Var tagging element as in Step 1.
  3. Click on the Value button in Field Properties and open Xpath editor.
  4. Insert the expression. We are using the var-element-value('LineRunningTotal') function to read the current value of the variable, whos name is passed as a string to the function parameter. Then we add the value of the @LineAmount field of the current data context. The result is stored back to the same variable.

Step 3: Insert the Field tagging element where the running total will be displayed

  1. Insert the Field taggin element where you want the runnint total to appear.
  2. Click on the Value button in Field Properties and open Xpath editor.
  3. Insert the expression. We are using the var-element-value('LineRunningTotal') function to read the current value of the variable.

Step 4: Format the field, add currency and run the preview

Set the Format String to d2, add another Field tagging element to display currency and set the color of both Fields to gray and click the Docentric AX > Preview button. You should see the preview with the result as shown in the beggining of this manual.

Limitations

MS Word documents are so-called flow documents. This means that their pagination is not fixed in the document but is calculated on the fly, depending on the page size, orientation and context size. For that reason it is unfortunatelly not possible to create page running totals.

IN THIS ARTICLE