All docs
V19.2
20.2
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.
A newer version of this page is available. Switch to the current version.

Custom Aggregate Functions

  • 3 minutes to read

Overview

XPO supports standard aggregate functions (Min, Max, Sum, Avg, Simgle, Exists, and Count) and custom aggregate functions.

To use custom aggregate functions, you need to:

For more details on how to implement and use custom aggregate functions, refer to the How to: Implement and Use Custom Aggregate Functions article and the How to Implement Custom Aggregates example.

Implement a Custom Aggregate Function

Define a class that implements the ICustomAggregate interface to create an aggregate that accepts a collection of values, uses an expression or several expressions to evaluate the values, and returns one result.

public class CountDistinctCustomAggregate : ICustomAggregate {
}

To use base and advanced functionality, implement one or several of the following ICustomAggregate descendants:

Register a Custom Aggregate Function

To enable a custom aggregate function, register it in the application. Choose one of the following methods:

If you need to register several functions, use the methods below:

When you no longer need the custom aggregate function or need to hide it from the UI, you can unregister it from the application with one of the corresponding methods below:

Call a Custom Aggregate Function in Criteria Operator Syntax

To use a custom aggregate function, you can call it directly:

[CollectionProperty][].MyCustomAggregate(property)

Alternatively, you can pass the custom aggregate function's name as one of the parameters:

[CollectionProperty][].AGGREGATE('MyCustomAggregate', property)

An aggregate is considered top-level if it is applied to the parent collection. If a custom aggregate is top-level, use the following syntax:

[].MyCustomAggregate(property)

[].AGGREGATE('MyCustomAggregate', property)

AGGREGATE('MyCustomAggregate', property)

XPO supports custom aggregates with any number of arguments or expressions - as compared to standard aggregates that accept one or no arguments, like Sum(value) or Count().

As a best practice, capitalize .AGGREGATE calls.

See Also