Aggregated Calculated Columns
Summary
- Aggregated Calculated Columns show a value that is derived dynamically from multiple, distinct rows
Most Calculated Columns use a Standard Scalar, basing the calculated value on other cells in the row.
However Calculated Column values can also be derived dynamically from multiple, distinct rows.
In this use case the Expression is of type Aggregation.
Like a Standard Scalar Expression, the Aggregated Scalar Expression returns a single scalar value.
Note
Aggregated Scalar Expressions can accept Scalar Expressions as inputs
Each value returned is calculated by aggregating multiple rows and columns in the grid.
Hint
A Calculated Column's Aggregated Scalar Expression updates in real time when a referenced grid value changes
Aggregation Operations
The following Aggregation operations are supported by AdapTableQL:
-
SUM: sums the values of the specified columns -
PERCENTAGE: calculates the percentage of the specified columns (usingSUMas default) -
AVG: calculates average of specified columns (optionalWEIGHTparameter supports Weighted Averages) -
MIN: returns the minimum value of the specified columns -
MAX: returns the maximum value of the specified columns
Caution
- Aggregated Calculated Columns cannot be used when using the Server-Side Row Model
- This is because they might not have all the rows on the client when performing the calculation
- This demo contains 5 Calculated Columns that use Aggregation Expressions - all on the
Github WatchersColumn:Sum Watchers- sums all the valuesAverage Watchers- average of all the valuesMin Watchers- Minimum of the valuesMax Watchers- Maximum of the values% Watchers- Percentage of the values
- Note these Calculated Columns do not use grouping - see demo below for an example using Groups
Expand to see the Aggregation Scalar Expressions
- Update a cell in the
Github Watcherscolumn and see how all 5 Calculated Columns update
Using GROUP_BY
An Aggregation Scalar Function can also be applied to a set of rows, rather than to the entire grid.
This is done by using the GROUP_BY AdapTableQL Expression Function.
This allows for much more powerful Expressions than displayed in the example above, becauase you can have multiple sets of Aggregations.
Find Out More
See the AdapTableQL Guide to Aggregation Expressions for more information and examples
- This demo contains 3 Calculated Columns that use Aggregation Expressions
- All are based on the
Github WatchersColumn and all use grouping on theLanguageColumn:Sum Watchers- sums all the valuesAverage Watchers- average of all the values% Watchers- Percentage of the values
- It also contains another Aggregated Scalar Calculated Column -
Open/Closed Issues Percentage by Language- This calculates the percentage of open and closed issues of all the repos in the grid, grouped by language
- It's a slightly contrived example, but showcases how to calculate a percentage based on aggregated values from other columns
Expand to see the Aggregation Scalar Expressions
Update a cell in the Github Watchers column and see how the Calculated Columns update
Grouped Rows
The values in Aggregation Calculated Columns can be used when summarising data for Grouped Rows.
AdapTable will ensure that if the Grid contains Aggregated Calculated Columns and Grouped Rows, the "aggFunc" summaries will display normally.
Deep Dive
A note on terminology
- This demo contains 4 Calculated Columns that use Aggregation Expressions based on the
Github WatchersColumn - Like in the demo above all the Aggregated Scalar Expressions use
GROUP_BYon theLanguageColumn - We have also created a Layout which contains Row Grouping on the Language Column
- The Layout also contains 4 AG Grid
aggFuncsummaries each connected to an AdapTable Aggregated Expression:SumByLang- uses aSUMAdapTable Aggregated Expression and asumAG Grid aggFuncAvgByLang- uses aAVGAdapTable Aggregated Expression and aavgAG Grid aggFuncMinByLang- uses aMINAdapTable Aggregated Expression and aminAG Grid aggFuncMaxByLang- uses aMAXAdapTable Aggregated Expression and amaxAG Grid aggFunc
- We have created an AG Grid Column Group to display the 4 Calculated Columns as a set
Update a cell in the Github Watchers Column and note how the 4 Calculated Columns update and so does the AG Grid agg summary