Skip to main content

Custom Aggregate Functions

  • 2 minutes to read

Total summaries provide five predefined aggregate functions. These functions allow you to calculate:

  • the number of records
  • the maximum and minimum values
  • the sum and the average value

ASPxVerticalGrid provides the ASPxGridBase.CustomSummaryCalculate event that enables you to implement custom aggregate functions or calculate summary values using a custom algorithm. Custom summaries allow you to:

  • calculate summaries against records that meet specific criteria
  • involve multiple data fields in calculations
  • implement complex summary functions (e.g., the standard deviation of a population), etc.

General Information

To calculate a summary manually:

The ASPxGridBase.CustomSummaryCalculate event fires for each record involved in summary calculation; when calculating a total summary value, the event is raised for each record; to enable you to perform any initialization and finalization, the event is raised before and after the processing of records

The summary calculation consists of three stages.

  • Initialization

    The CustomSummaryCalculate event is raised once and the SummaryProcess property is set to CustomSummaryProcess.Start. At this stage, you can initialize summary values (e.g., reset internal counters).

  • Calculation

    The CustomSummaryCalculate event fires multiple times, once for each record in a grid. The SummaryProcess property is set to CustomSummaryProcess.Calculate. At this stage you should accumulate summaries.

    The event parameter properties allow the processed record and its values to be obtained.

  • Finalization

    The CustomSummaryCalculate event is raised once and the SummaryProcess property is set to CustomSummaryProcess.Finalize. At this point, calculate a final summary value and assign it to the event parameter’s TotalValue property.

To determine the current stage, use the event parameter’s SummaryProcess property.

To skip the Calculation stage and calculate a custom summary at the Initialization or Finalization stage, set the event parameter’s TotalValueReady property to true at the Initialization stage. This automatically skips the Calculation stage and the Finalization stage starts immediately.