The grouping basically transform the output as below:
- Splits the initial set into subsets where all instances in a subset have the same values for the grouping properties specified in the first parameter,
- Applies set transformations to each subset according to the second parameter, resulting in a new set of potentially different structure and cardinality,
- Ensures that the instances in the result set contain all grouping properties with the correct values for the group,
- Concatenates the intermediate result sets into one result set.
In its simplest form the first parameter specifies the grouping properties, a comma-separated list of one or more single-valued property paths (paths ending in a single-valued primitive, complex, or navigation property) that is enclosed in parentheses. The same property path SHOULD NOT appear more than once; redundant property paths MAY be considered valid, but MUST NOT alter the meaning of the request. If the property path leads to a single-valued navigation property, this means grouping by the entity-id of the related entities.
The optional second parameter is a list of set transformations, separated by forward slashes to express that they are consecutively applied. Transformations may take into account the grouping properties for producing their result, e.g. aggregate removes properties that are used neither for grouping nor for aggregation.
If the service is unable to group by same values for any of the specified properties, it MUST reject the request with an error response. It MUST NOT apply any implicit rules to group instances indirectly by another property related to it in some way.
Request the list of invoice aggregation based on date.
/api/v1/SalesInvoices?$apply=groupby((Entity/id),aggregate(BaseInvoiceAmount with sum as Total)))
These are the most basic requirements illustrated in above examples. OData offers extensive flexibility in data retrieval. Much more examples can be found to cater various other needs in OData Version 4.0.