DynamicWhere.ex
DynamicWhere.exv2.1.5·docs

AggregateBy

An AggregateBy represents one aggregation inside a GroupBy. It produces a single output column named by its Alias.

Properties

PropertyTypeDescription
Fieldstring?Property to aggregate (optional for Count).
Aliasstring?Name of the result column (must not conflict with GroupBy.Fields, no dots).
AggregatorAggregatorAggregation function.
Alias rules
  • Alias must be a plain identifier — a leading letter or underscore, then letters, digits, or underscores. Letters are matched by Unicode category, so a non-Latin alias such as "المجموع" is valid. It becomes a top-level property on the resulting dynamic objects in SummaryResult.Data. Anything else — a dot, comma, space, or dash — throws AggregationMustHasValidAlias (tightened in 2.1.4; see breaking changes).
  • Alias must not collide with any field name in GroupBy.Fields.
  • Field is required for every aggregator except Count.

C# example

var aggregations = new List<AggregateBy>
{
    new AggregateBy { Aggregator = Aggregator.Count, Alias = "OrderCount" },
    new AggregateBy { Field = "Amount", Aggregator = Aggregator.Sum, Alias = "Revenue" },
    new AggregateBy { Field = "Amount", Aggregator = Aggregator.Avg, Alias = "AverageAmount" }
};

JSON example

[
  { "aggregator": "Count", "alias": "OrderCount" },
  { "field": "Amount", "aggregator": "Sum", "alias": "Revenue" },
  { "field": "Amount", "aggregator": "Avg", "alias": "AverageAmount" }
]

See also