# Aggregation

## Content

**FlexGrid** provides selection statistics, which can be used to display Excel-style data summaries in the footer. It allows you to display the statistics of the basic functions and operations performed on the selected cell range. These functions or operations include aggregate operations such as sum, average, count, maximum number, minimum number, and count distinct which can be applied to the selected cells from the context menu. You can use the [Aggregate](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.Column.Aggregate.html) property of the [AggregateDefinition](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.AggregateDefinition.html) class to provide data summary for the selected cell range.
![](https://cdn.mescius.io/document-site-files/images/2f10b028-0ae8-4c29-a102-4d67578c339b/images/selection-statistics.png)

The [Aggregate](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.Column.Aggregate.html) property uses [AggregateEnum](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.AggregateEnum.html) enumeration to set the aggregate function to be applied on the cells by setting one of the following values:

* **Average**: Displays the value of the non-empty cells in a range.
* **Sum**: Displays the sum of all values in the range.
* **Clear**: Clear the existing aggregates
* **Count**: Displays the total number of non-empty cells in a range.
* **CountDistinct**: Displays the count of unique non-empty cells in a range.
* **Min**: Displays the minimum value in a range.
* **Max**: Displays the maximum value in a range.
* **Percent**: Displays the percentage value of the grand total.
* **Std**: Displays the sample standard deviation of the values in a range.
* **Var**: Displays the sample variance of the values.
* **StdPop**: Displays the population standard deviation of the values in a range (uses the formula based on n).
* **VarPop**: Displays the population variance of the values in a range (uses the formula based on n).
* **Aggregate**: No aggregate.

To show the selection statistics at the footer of the grid, we have added a ToolStripLabel named 'tslSelectionStatistics' docked at the bottom of the grid. Then, add the below code to the [SelChange](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.C1FlexGridBase.SelChange.html) event of the [C1FlexGridBase](/componentone/api/win/online-flexgrid/dotnet-api/C1.Win.FlexGrid.10/C1.Win.FlexGrid.C1FlexGridBase.html) class. This event fires when the user extends the selection with the mouse in the grid.

```csharp
private void c1FlexGrid1_SelChange(object sender, EventArgs e)
{
    var text = string.Empty;
    if (!flexGrid1.Selection.IsSingleCell)
    {
        text = $"Average: {flexGrid1.Aggregate(AggregateEnum.Average):F2}  " +
       $"Count: {flexGrid1.Aggregate(AggregateEnum.Count)}  " +
       $"Summary: {flexGrid1.Aggregate(AggregateEnum.Sum):F2}";
    }
    //Gets the text to be displayed on the toolstrip label 
    tslSelectionStatistics.Text = text;
}
```