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 (using SUM as default)

  • AVG: calculates average of specified columns (optional WEIGHT parameter 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
Calculated Columns: Aggregated
Fork
  • This demo contains 5 Calculated Columns that use Aggregation Expressions - all on the Github Watchers Column:
    • Sum Watchers - sums all the values
    • Average Watchers - average of all the values
    • Min Watchers - Minimum of the values
    • Max 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

Try It Out
  • Update a cell in the Github Watchers column 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

Calculated Columns: Aggregated with GROUP_BY
Fork
  • This demo contains 3 Calculated Columns that use Aggregation Expressions
  • All are based on the Github Watchers Column and all use grouping on the Language Column:
    • Sum Watchers - sums all the values
    • Average 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

Try It Out

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

Calculated Columns: Aggregated with Row Grouping
Fork
  • This demo contains 4 Calculated Columns that use Aggregation Expressions based on the Github Watchers Column
  • Like in the demo above all the Aggregated Scalar Expressions use GROUP_BY on the Language Column
  • We have also created a Layout which contains Row Grouping on the Language Column
  • The Layout also contains 4 AG Grid aggFunc summaries each connected to an AdapTable Aggregated Expression:
    • SumByLang - uses a SUM AdapTable Aggregated Expression and a sum AG Grid aggFunc
    • AvgByLang - uses a AVG AdapTable Aggregated Expression and a avg AG Grid aggFunc
    • MinByLang - uses a MIN AdapTable Aggregated Expression and a min AG Grid aggFunc
    • MaxByLang - uses a MAX AdapTable Aggregated Expression and a max AG Grid aggFunc
  • We have created an AG Grid Column Group to display the 4 Calculated Columns as a set
Try It Out

Update a cell in the Github Watchers Column and note how the 4 Calculated Columns update and so does the AG Grid agg summary

Aggregated Calculated Columns

(Recorded with AdapTable v12.0)