Berserk Docs
Aggregate Functions

Introduction to Aggregate Functions

Aggregate function overview and categories

Aggregate functions combine multiple rows into a single summary value. They are used inside the summarize operator:

logs
| summarize
    total = count(),
    error_rate = countif(severity_number >= 17) * 1.0 / count(),
    p95 = percentile(duration_ms, 95)
  by service, bin(timestamp, 5m)

Each aggregate collapses the rows in a group into one output row. The by clause defines the grouping keys. For a full introduction to writing queries, see Writing Queries.

Statistical

FunctionDescription
avgCalculates the average of values in the group.
countReturns a count of the records in the input record set.
countifReturns a count of the records for which a predicate is true.
dcountReturns an estimate for the number of distinct values of the expression in the group.
dcountifReturns an estimate for the number of distinct values of the expression in the group, for which the predicate evaluates to true.
maxReturns the maximum value across the group.
minReturns the minimum value across the group.
stdevCalculates the sample standard deviation of values in the group.
stdevifCalculates the sample standard deviation of values for which the predicate is true.
stdevpCalculates the population standard deviation of values in the group.
sumCalculates the sum of values in the group.
take_anyReturns an arbitrary non-null value from the group.
take_anyifReturns an arbitrary non-null value from the group for which the predicate is true.

Arg

FunctionDescription
arg_maxReturns both the maximum value and the corresponding return expression from the row where the first expression is maximum.
arg_minReturns both the minimum value and the corresponding return expression from the row where the first expression is minimum.

Make / Collect

FunctionDescription
firstReturns the value of the expression from the row with the earliest timestamp.
lastReturns the value of the expression from the row with the latest timestamp.
make_listReturns a dynamic (JSON) array of all values of Expr in the group.
make_setReturns a dynamic (JSON) array of all distinct values of Expr in the group.

Percentile & Sketch

FunctionDescription
hllCreates a HyperLogLog sketch.
hll_ifCreates a HyperLogLog sketch for records where the predicate evaluates to true.
hll_mergeMerges multiple HyperLogLog sketches.
merge_tdigestMerges multiple T-Digest sketches.
percentileCalculates the specified percentile.
tdigestCreates a T-Digest sketch from numeric values.

Metrics

FunctionDescription
counter_rateComputes per-second rate from OpenTelemetry cumulative counters using start_time for reset detection.
derivComputes the derivative (rate of change) for a gauge metric.
rateComputes the per-second rate of change for a counter metric, handling counter resets.

Other

FunctionDescription
describe_schemaInfers JSON Schema from column values.

On this page