Calculated values
A calculation expresses a relationship between fields by setting the value of a calculated field based on one or more input fields. For example, an online shopping cart application provides customers a total cost for each item ordered, based on unit price and quantity ordered, then calculates a total for all the items ordered.
The application then calculates any assessed tax and adds the tax to the order total to calculate the final charge to the customer. Other calculations can determine the value of promotional discounts and frequent shopper points. Calculation occurs whenever users update the value of an input field. Defining a field calculation reduces the chance for error and improves process efficiency by eliminating the need for a manual calculation.
You can use a calculated field as an input to another calculation, creating a network of dependent calculations. When a user updates the value of a field that serves as a calculation input, the resulting calculation can trigger additional calculations for dependent fields.
The three types of calculations are:
- Functions iterate over items in a list.
- Expressions calculate a field value by referencing any combination of simple fields, complex fields, and data relationships.
- Decision tables use a set of conditions to test property values and return an appropriate response.
Check your knowledge with the following interaction:
Functions
Functions iterate over items in a data relationship and are supported for Decimal, Currency, and Integer Field Types. There are four basic functions for use in calculations:
- Sum of adds all items in the specified property instances
- Average of calculates the average value of all specified property instances
- Maximum of determines the largest value for all specified property instances
- Minimum of determines the smallest value for all specified property instances
Sum of
An online retailer needs to calculate a shopping cart total. As customers add items to an order, remove items from an order, or update the quantity of an item on an order, the application must update the total cost. You can use the Sum of function to calculate the Order total field value.
Average of
An online retailer wants to create an application dashboard to analyze customer spending patterns so managers can identify the territories that generate the most, and least revenue on a per-customer basis. You can create a list of submitted orders filtered by territory. You can then use the Average of function to identify the average order value.
Maximum of
An online retailer needs to allow customers to apply a single promotional discount to an order. Customers submit one or more promotional codes to apply various discounts, such as 20% off the most expensive item or waiving the shipping charge for an order over a specified amount. You can create a promotional discounts data reference, where each item in the list identifies the promotional code and the discount value. You can then use the Maximum of function to determine the most valuable promotional discount to apply to the order.
Minimum of
An online retailer needs a promotion where preferred customers receive the lowest-cost item from a list of approved free items when placing an order. You can use the Minimum of function to identify the lowest-cost item in the order, and then apply a credit to the order in that amount.
Expressions
You can create an expression to calculate the field value by using any number of simple fields, complex fields, or data relationship values. As seen in the following figure, an online ordering application calculates the total cost of the transaction by adding the cost of the TeamHats and the cost of TeamMagnets:
When you create an expression, you reference fields by name using the dot operator ("."). This operator provides a list of all fields that are available in the context of the current case. If the field is part of a data relationship, add the property name or list as a prefix.
Expressions support common operations, such as:
- Addition
- Subtraction
- Multiplication
- Division
- Grouping (using parenthesis)
- Boolean AND
- Boolean OR
For example, you can calculate the order tax by multiplying the tax rate by the order total.
You can define an expression for any Simple Field Type. For text-based formats, you can assemble a text string by using a process known as concatenation. For example, an appraisal firm offers to estimate the value of collectible items for customers who submit an item for review. The firm wants to add a comment to the page displaying the item, noting the following information:
- Appraised item name
- Approximate valuation
- Appraiser ID
You can define a calculation to assemble the comment by using a combination of field references and static text, where the static text is enclosed with quotation marks (").
When evaluating the calculation, the application replaces the reference to each field with the current field value. The calculation creates a string similar to the following example:
Appraiser 04795AD appraised Silver platter at a value of USD 350.
Decision tables
Decision Tables are a type of business rule that evaluate the values of one or more fields against a set of conditions to determine a result. They organize logic in a structured, tabular format, where each row represents a possible outcome based on specific criteria. For example, to determine an interest rate for a loan, the application evaluates the selected loan type against predefined conditions. The Decision Table returns the appropriate rate, which is then used to derive the value displayed in the user interface.
The following image shows setting up a Decision table:
Calculation networks
A network of calculations is established and maintained to identify and manage relationships between fields within an application. When a field calculation is defined, it becomes part of a network of related calculations that connect dependent fields. This network enables values to remain synchronized by automatically propagating changes across all related fields. As a result, when one value changes, all dependent calculated fields reflect the updated information. For example, in a shopping cart, a change in item quantity can trigger updates to related calculated values, such as totals or pricing summaries, ensuring consistency across the application.
Match the numbers to the following image to see the functions that trigger the shopping cart calculations:
1. Line total calculation: Users add an item to the list or update the quantity of an item already in the list. Line total is calculated as .UnitPrice * .Quantity.
2. Order total calculation: The updated line total triggers a calculation to update the order total, using the Sum of function to add each line total in the list of items.
3. Tax calculation: The updated order total triggers a calculation to update the tax applied to the order as the value of .TaxRate * .OrderTotal.
4. Total cost calculation: The updated tax amount triggers a calculation to update the total cost as the value of .Tax + .OrderTotal.
Check your knowledge with the following interaction:
This Topic is available in the following Module:
Want to help us improve this content?