FireDAC.Comp.DataSet.TFDAggregate.Expression
Delphi
property Expression: String read FExpression write SetExpression;
C++
__property System::UnicodeString Expression = {read=FExpression, write=SetExpression};
Contents
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 |
---|---|
|
Summarizes the argument values. |
|
Returns the minimal argument value. |
|
Returns the maximal argument value. |
|
Computes the average value of an argument, which is the total of all values, divided by the count of all non-NULL values. |
|
Returns the count of all non-NULL argument values, if the argument is specified. Otherwise, it returns the count of all records. |
|
Returns the first argument value. |
|
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';