Documentation

Aggregate Functions

Aggregate functions automatically calculate summary values for grouped data in your tables. Simple Table supports built-in aggregations like sum, average, count, min, max, and custom functions to provide powerful data insights with automatic computation and formatting.

Basic Implementation

Aggregate functions are configured by adding the aggregation property to column headers. When data is grouped using row grouping, these functions automatically calculate summary values for each group level.

Aggregation Configuration

PropertyRequiredDescriptionExample
HeaderObject.aggregation
Optional
Configuration object for aggregation functions that automatically calculate summary values for grouped data. Supports built-in types (sum, average, count, min, max) and custom functions.
Options:
sum
average
count
min
max
custom

Aggregation Types

Sum Aggregation

Calculates the total of all numeric values in a group.

{
  aggregation: { type: "sum" }
}

Perfect for totaling budgets, employee counts, or any cumulative metrics.

Average Aggregation

Computes the arithmetic mean of all values in a group.

{
  aggregation: { type: "average" }
}

Ideal for ratings, performance scores, or any metric where the mean is meaningful.

Count Aggregation

Counts the number of non-null values in a group.

{
  aggregation: { type: "count" }
}

Useful for counting projects, tasks, or any discrete items within groups.

Min/Max Aggregation

Finds the minimum or maximum value in a group.

{
  aggregation: { type: "min" }
}
// or
{
  aggregation: { type: "max" }
}

Great for finding ranges, extremes, or boundary values in your data.

Advanced: Custom Aggregation & Value Parsing

For complex scenarios, you can define custom aggregation functions and parse string values before aggregation.

Custom Function

{
  aggregation: {
    type: "custom",
    customFn: (values: any[]) => {
      // Calculate weighted average or any custom logic
      const sum = values.reduce((acc, val) => acc + parseFloat(val), 0);
      return Math.round((sum / values.length) * 10) / 10;
    }
  }
}

Value Parsing

{
  aggregation: {
    type: "sum",
    parseValue: (value: string) => {
      // Parse "$15.0M" to 15.0
      const numericValue = parseFloat(value.replace(/[$M]/g, ""));
      return isNaN(numericValue) ? 0 : numericValue;
    }
  }
}

💡 Pro Tips

  • Combine aggregations with custom cell renderers to format results appropriately
  • Use parseValue when your source data contains formatted strings like currencies
  • Aggregations work at every level of row grouping, providing hierarchical summaries
  • Custom aggregation functions receive all values in the group as an array