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

Add-ons

Scaffolding

Platform

Server, Data Center

Macros
Suppliers

Guide

  1. Insert a Table Data macro and name it "purchaseTable".
    Edit the parameters of the macro so its Initial Rows is 1.
     
  2. Inside the Table Data macro, create a table like this:
     

    ItemUnit PriceQuantityTotal Price






  3. Now insert Text Data, Number Data and Eval Data macros into the table, like in the image below:



    For this example, we will give the macros the following names:



  4. In the Eval Data macro, type the following code:
     

    ${unitPrice} * ${quantity}


    The Eval Data macro should now look like this:



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

  6. 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:




  7. 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 Eval Data macros for each of the values above and give them relevant names, like in the following image:



  8. For each of these Eval Data macros, enter the following in the Display Format properties:

    $ #,##0.00
  9. Type in the following codes in the respective Eval Data macros:

    Net Total

    sumtable("purchaseTable","totalPrice")

    Discount Amount

    ${netTotal} * ${discount} / 100

    Tax Amount

    ${netTotal} * ${tax} / 100

    Grand Total

    ${netTotal} - ${discAmt} + ${taxAmt}


    Your Eval Data macros should look something like this:



  10. Now save the page, and click Edit Contents.

  11. Fill in the numbers and check out the results! 

Result

Purchase Order

ItemUnit PriceQuantityTotal Price

Playstation 4

$ 399.00
5
$ 1,995.00

Xbox One X

$ 499.99
2
$ 999.98

Switch

$ 299.00
7
$ 2,093.00

Net Total (excluding tax and discount) :

$ 5,087.98

Discount Amount :

$ 508.80

Tax Amount : 

$ 25.44

Grand Total (including tax and discount) :

$ 4,604.62