From RAD Studio API Documentation
Jump to: navigation, search


property Aggregates: TFDAggregates read FAggregates write SetAggregates stored IsAS;


__property TFDAggregates* Aggregates = {read=FAggregates, write=SetAggregates, stored=IsAS};


Type Visibility Source Unit Parent
property public
FireDAC.Comp.DataSet TFDDataSet


The collection of client-side aggregates defined for the dataset.

Use Aggregates to define the client-side aggregating formulas, which are automatically maintained and calculated for a group of records or for all the records in the dataset. 

All the records in the group of records have the same field values for the defined set of fields. The Aggregates property computes for groups of records that are associated with one of the indexes. These aggregate expressions will be calculated only if the associated index is current and active. 

Adding an ggregate field does not add a TFDAggregate object to the Aggregates collection. There are two alternative ways: to use aggregate fields or to use Aggregates

DataSet automatically maintains and computes the Aggregates values when the dataset is fetching the data or the application edits the data, if AggregatesActive is True. If the application needs to perform large updates to the dataset and aggregate values are not needed while updating, then set AggregatesActive to False before updating, and return to the original value after updating. Also, see the BeginBatch and EndBatch methods. 

When aggregates are maintained, the Value method of every active aggregate object returns a value that reflects the current data in the dataset. When users edit the data in the dataset, these values are recalculated to reflect the users' changes. 

The expressions in Aggregates must contain aggregating functions, such as SUM, COUNT. FireDAC supports extended expression syntax.


with FDMemTable1.Aggregates.Add do begin
  Expression := 'sum(sal + bonus)';
  Active := True;
with FDMemTable1.Aggregates.Add do begin
  Expression := 'sum(sal + bonus)';
  IndexName := 'by_deps';
  Active := True;
FDMemTable1.IndexName := 'by_deps';
FDMemTable1.AggregatesActive := True;

Label1.Caption := 'Total payments : ' + VarToStr(FDMemTable1.Aggregates[0].Value);
Label2.Caption := 'Current department payments : ' + VarToStr(FDMemTable1.Aggregates[1].Value);

See Also