Calculated columns are custom columns that you create (at design or run time) where the value is not in the underlying dataset but is dynamically derived from other cells in the row.
You create Calculated Columns via the Expression Editor where you can drag and drop the Columns and functions you need, or write the expression by hand.
A Calculated Column contains a Scalar Expression, meaning that it can return any single value, and it will update automatically as other values change.
In this example we have created 6 Calculated Columns:
- Avg Item Cost - (numeric) which divides ItemCost by ItemCount
- Profit - (numeric) which calculates Invoiced Cost minus sum of Order Cost and Package Cost
- Comment - (a string) which returns 'Low' if ItemCost is less than 50, 'Medium' if greater than 50 and 'High' if greater than 100.
- Highest Cost - (a number) which returns the largest of ItemCost, OrderCost, InvoicedCost and PackageCost (the latter being first multiplied by 10)
- ShipDelay - (a boolean) which returns true if ShippedDate is 4 days later than theOrderDate (we add it to CheckboxColumns in Format Column Module for better visualisation).
- Tax - (a number) which returns the VAT (calculated at 20%) on Profit (which is also a Calculated Column!) and to which we've added a Display Format
Click the 1st button in Dashboard to see details of the Expression - or 'Edit Expression' in the Column Header menu.
Calculated Columns are treated as 'normal' columns and can be referenced in other AdapTable objects. In this demo these Calculated Columns are referenced elsewhere:
- Comment in the grouped calc cols layout
- Profit in 2 Conditional Styles which use Predicates (Positive and Negative)
- High Cost in a Row-based Conditional Style that uses an Expression
so we included them in the layouts we created (and we grouped on 'Comment') and we also styled them (e.g. 'Profit') using Conditional Styles.