Storing Data and Using that Data for Calculations
Let's create a table that can store number data. These numbers can then be used to calculate other values.
Ingredients
Apps | Scaffolding |
---|---|
Macros | Table Data |
Guide
- Insert a Table Data macro and name it "purchaseTable".
Edit the parameters of the macro so its Initial Rows is 1. Inside the Table Data macro, create a table like this:
Item Unit Price Quantity Total Price Now insert Text Data, Number Data and Evaluate Data macros into the table, like in the image below:
For this example, we will give the macros the following names:- Text Data: item
- Number Data: unitPrice
- Number Data: quantity
- Evaluate Data: totalPrice
In the Evaluate Data macro, type the following code:
${unitPrice} * ${quantity}
CODEThe Evaluate Data macro should now look like this:
Now, underneath the Table Data macro you created in Step 1, create a Hidden Data macro.
The Hidden Data macro is used when you want to enter data that you would rather not show to the reader of the page.
- In the Hidden Data macro, create 2 Number Data macros and name them "discount" and "tax".
With each Number Data macro, click Allow Decimal Values.
It should look something like this: - It's now time to make Scaffolding do some math.
Let's calculate:- Net Total (excluding tax and discount)
- Discount Amount
- Tax Amount
- Grand Total (including tax and discount)
Create four Evaluate Data macros for each of the values above and give them relevant names, like in the following image:
For each of these Evaluate Data macros, enter the following in the Display Format properties:
$ #,##0.00
CODEType in the following codes in the respective Evaluate Data macros:
Net Totalsumtable("purchaseTable","totalPrice")
CODEDiscount Amount
${netTotal} * ${discount} / 100
CODETax Amount
${netTotal} * ${tax} / 100
CODEGrand Total
${netTotal} - ${discAmt} + ${taxAmt}
CODE
Your Evaluate Data macros should look something like this:Now save the page, and click Edit Contents. Input the values "10" and "0.5" respectively for the Discount percentage and Tax percentage fields.
You will get the desired results.