

I’m wondering whether you would like to add an automatic money calculation function to the workflow App for goods purchasing requests. The App will allow you to calculate not only the total and subtotal, but also to change the formula depending on the conditions.
In this post, I would like to illustrate how to implement a system that not only calculates the total amount based on the purchase list but also does a discount calculation which deducts 50% from payments exceeding $1000 of the total amount using a split in the workflow diagram. A Table-type Data Item and a Update Data are vital elements for the design of this App.
Calculation of the Total Amount with a Table-type Data Item
First of all, we’d like you to create an App, setting a Table-type Data Item for listing the purchased items and make it calculate the total automatically.
Workflow Diagram
Please create a new App and set up the workflow diagram as follows:

Data Items
Let’s prepare the following data items.
| Data Item Name | Data-type | Field Name | Remarks |
| Title | – | ||
| Purchase list | Table | q_purchase_list | Set the 4 sections, Description (String)/ Unit Price (Numeric)/ Quantity (Numeric)/ Subtotal (Numeric) |
| Total | Numeric-type | q_total | Automatically input the total value of: Purchase list–Subtotal |
Purchase List Settings
In Purchase List (Table-type Data Item) set up 4 table columns, which are labelled Description, Unit Price, Quantity, and Subtotal respectively.

In the Subtotal column the subtotal of each row in the table is calculated and saved. Check the “Show total value at the bottom of list” box as well. In addition, it is mandatory to set the Field Name for a column that is set to display the sum. Please be sure to set it. (This Field Name does not have to start with “q_”.)

Then you should set up a Numeric-type Data Item that saves the total value of the Table-type Data Item using the arithmetic expression settings window. The expression is automatically inserted into the text box.

Data editing permission Settings
Please set up as in the following figure.
| Enter | Confirmation | |
| Title | Editable | Only display |
| Purchase list | Editable | Only display |
| Total | No display | Only display |
You’ve created an app that calculates the total amount from the Purchase list using a Table-type Data Item. Please exit editing and release it now to see how it works.

When you finish the Task after entering the unit price and quantity of an item in the Purchase list, the total amount will be saved in the Total section.
Discount Calculations Using Update Data
Now let’s implement a workflow that performs automatic calculations under the condition of a 50% discount for payments where the total is over $1000.
Workflow Diagram
Let’s add some changes to the initial workflow diagram that you made as follows:

Set an Update Data icon in each split flow where the condition of the Task is set to more than $1000 and less than $1000 in the total amount. That enables the token to advance to the Task and set the condition of a 50% discount for payments exceeding $1000 in the total amount.
Settings in Exclusive Gateway (XOR)
You use an Exclusive Gateway (XOR) to control the flow based on whether the total amount is over $1000.

You have to add a flow for cases of over $1000 and set its destination to “Discount”, whereas you set the destination of the Default Flow to “No Discount”.
For the condition of the Total which is set over $1000, the Conditional Expression Setting is set as follows.

This setting enables the token to advance to the Discount Processing Task if the Total is $1000 or more, whereas the token advances to the No Discount Task if the total is less than $1000.
Data Item Settings
Please add a Numeric-type Data Item called “Total Discounted Amount” to save the discounted total.
| Data Item Name | Data-type | Field Name | Remarks |
| Total Discounted Amount | Numeric-type | q_discounted_total |
| Enter | Confirmation | |
| Total Discounted Amount | No display | Only display |
Settings in Update Data
Let’s set up two Update Data Steps respectively for the No Discount and Discount branches.
No Discount
Set up an expression for the Total which is less than $1000. Since it will not apply any discount, the value of Total should be saved in the Total Discounted Amount data item.

Discount
Set up an expression for the Total which is over $1000. A 50% discount is given to the amount over $1000 so the expression is set as follows:
100000 + (#q_total - 100000) * 0.5

* For the Numeric-type, numbers below the range of decimal digits specified in the settings of the Data item are truncated (e.g. if the range of decimal digits is 0, then the result of 1.5 (3 * 0.5) becomes 1 due to rounding down the first decimal place). The same thing will perform in the Numeric-type item in the table columns.
The settings of the App are now complete. You have to exit editing and release it to see how it works. In particular, I would like you to check that splitting by the Total is working and check for any mistakes in discount calculations.


In this instance, because the calculation expression needs to change depending on whether the Total is $1,000 or more, the discount calculation was performed using [Update Data]. While calculations can also be defined via the [Expression] setting for Numeric-type Data Items, that method does not allow the expression to change based on conditions. For information on how to use [Expression], please refer to Automatically Calculate the Value of a Numeric-type Data Item Using an Expression.


