AggregateOperand.Avg(CriteriaOperator) Method
Creates a new AggregateOperand which returns the average of values calculated by the given aggregate expression. This expression is evaluated against elements of the AggregateOperand.CollectionProperty that match the specified AggregateOperand.Condition.
Namespace: DevExpress.Data.Filtering
Assembly: DevExpress.Data.v24.2.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
aggregatedExpression | CriteriaOperator | A CriteriaOperator object which specifies the aggregate expression. |
Returns
Type | Description |
---|---|
AggregateOperand | An AggregateOperand object which calculates an aggregate expression. |
Example
Example 1
Get average value of price property of all orders.
Expression:
CriteriaOperator.FromLambda<Order, double>(x => FromLambdaFunctions.TopLevelAggregate<Order>().Average(c => c.Price));
Input:
Name | Price |
---|---|
Item0 | 10 |
Item1 | 20 |
The result: 15
Example 2
Get list of orders with average order item price more than 100.
Expression:
CriteriaOperator.FromLambda<Order>(x => x.OrderItems.Average(t => t.ItemPrice) > 100);
Input:
Order | OrderItem | OrderItemPrice |
---|---|---|
Order0 | ||
Item0-0 | 10 | |
Item0-1 | 20 | |
Order1 | ||
Item1-0 | 100 | |
Item1-1 | 200 | |
Order2 | ||
Item2-0 | 30 | |
Item2-1 | 40 | |
Order3 | ||
Item3-0 | 300 | |
Item3-1 | 400 |
The result:
Order |
---|
Order1 |
Order3 |