FireDAC.Comp.DataSet.TFDAggregate.Expression

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

property Expression: String read FExpression write SetExpression;

C++

__property System::UnicodeString Expression = {read=FExpression, write=SetExpression};

Properties

Type Visibility Source Unit Parent
property published
FireDAC.Comp.DataSet.pas
FireDAC.Comp.DataSet.hpp
FireDAC.Comp.DataSet TFDAggregate

Description

Specifies the expression to be calculated.

Use the Expression property to specify a formula text. The formula must contain aggregating functions, otherwise an exception is raised. The following aggregating functions are supported:

Function 

Description 

SUM 

Summarizes the argument values. 

MIN 

Returns the minimal argument value. 

MAX 

Returns the maximal argument value. 

AVG 

Computes the average value of an argument, which is the total of all values, divided by the count of all non-NULL values. 

COUNT 

Returns the count of all non-NULL argument values, if the argument is specified. Otherwise, it returns the count of all records. 

TFIRST 

Returns the first argument value. 

TLAST 

Returns the last argument value. 

The aggregating functions operate on field values or on expressions built from field values, constants, and scalar function calls, using the standard FireDAC expression syntax. However, several restrictions are applied:

Notes:

  • You can create expressions by using operators on aggregated values with other aggregated values or constants.
  • You cannot combine aggregated values with field values, because such expressions are ambiguous - there is no indication of which record should supply the field value.
  • You cannot nest aggregating functions.

The expression is automatically evaluated by FireDAC and the result is assigned to the Value property. All calculations are performed for the current group of the records. Use GroupingLevel to specify the grouping.

Example

// count number of records with Discount > 0
FDQuery1.Aggregates[0].Expression := 'COUNT(IIF(Discount > 0, 1, NULL))';

// OK
FDQuery1.Aggregates[0].Expression := 'COUNT(*) * 5';

// INVALID - cannot combine aggregating function with field
FDQuery1.Aggregates[0].Expression := 'AVG(Discount) * Amount';

See Also