{aggregate:function:ids_string:expression:parameter}

Description

MK{item:d1a7ad7db8dbc8da6cc9c9cf78f39acc:_#SEO_____}EMK

Parameters

function required default (none - required)

Which aggregation to apply. One of the allowed values below. An unknown function makes the whole expression return an empty string.

ids_string required default (none - required)

The set of items to aggregate over, given as their item ids joined by dashes. Empty or whitespace-only parts (and a bare 0) are dropped before lookup. Usually fed from {ids:...} or a relation field.

expression optional default (empty)

The value computed for each item, evaluated in that item's context (typically a field alias such as _#NUMBER__). For sum/max/min/avg it is read as a number; for concat/order/filter as a string. Optional - omit it for count, which only needs to know how many items there are.

parameter optional default (empty)

Extra argument whose meaning depends on the function: the glue string for concat (not trimmed, so spaces count), the sort mode for order (numeric | rnumeric | string | rstring | locale | rlocale), or the value/needle to match for the filter family. Ignored by sum/max/min/avg/count.

Examples

test{aggregate:count:a65d19971986e750761f0efcd9a16b1b-4f3362a62847fe1f8c59ba28a92d42c0-5726c2c6b035d7aab450d1794e9e90d7:}
Expected3
Actual3
count returns how many of the listed items resolved. With no expression it just counts the ids. Three valid item ids give 3.
test{aggregate:sum:a65d19971986e750761f0efcd9a16b1b-4f3362a62847fe1f8c59ba28a92d42c0-5726c2c6b035d7aab450d1794e9e90d7:_#NUMBER__}
Expected156
Actual156
sum reads the expression for each item, converts each to a number, and totals them. Alpha 14 plus Beta 42 plus Gamma 100 is 156.
test{aggregate:avg:a65d19971986e750761f0efcd9a16b1b-4f3362a62847fe1f8c59ba28a92d42c0-5726c2c6b035d7aab450d1794e9e90d7:_#NUMBER__}
Expected52
Actual52
avg is the arithmetic mean of the expression values. (14 + 42 + 100) / 3 = 52.
test{aggregate:max:a65d19971986e750761f0efcd9a16b1b-4f3362a62847fe1f8c59ba28a92d42c0-5726c2c6b035d7aab450d1794e9e90d7:_#NUMBER__}
Expected100
Actual100
max returns the largest expression value across the items. The largest of 14, 42, 100 is 100.
test{aggregate:min:a65d19971986e750761f0efcd9a16b1b-4f3362a62847fe1f8c59ba28a92d42c0-5726c2c6b035d7aab450d1794e9e90d7:_#NUMBER__}
Expected14
Actual14
min returns the smallest expression value across the items. The smallest of 14, 42, 100 is 14.
test{aggregate:concat:a65d19971986e750761f0efcd9a16b1b-4f3362a62847fe1f8c59ba28a92d42c0-5726c2c6b035d7aab450d1794e9e90d7:_#NUMBER__:, }
Expected14, 42, 100
Actual14, 42, 100
concat joins the expression values using the 4th parameter as glue. Parameters are not trimmed, so the glue can contain spaces.
test{aggregate:filter:a65d19971986e750761f0efcd9a16b1b-4f3362a62847fe1f8c59ba28a92d42c0-5726c2c6b035d7aab450d1794e9e90d7:_#NUMBER__:42}
Expected4f3362a62847fe1f8c59ba28a92d42c0
Actual4f3362a62847fe1f8c59ba28a92d42c0
filter keeps only items whose expression value equals the 4th parameter, and returns their item ids joined by dashes. Only Beta has value 42.
test{aggregate:order:5726c2c6b035d7aab450d1794e9e90d7-a65d19971986e750761f0efcd9a16b1b-4f3362a62847fe1f8c59ba28a92d42c0:_#NUMBER__}
Expecteda65d19971986e750761f0efcd9a16b1b-4f3362a62847fe1f8c59ba28a92d42c0-5726c2c6b035d7aab450d1794e9e90d7
Actuala65d19971986e750761f0efcd9a16b1b-4f3362a62847fe1f8c59ba28a92d42c0-5726c2c6b035d7aab450d1794e9e90d7
order returns the item ids re-sorted by the expression value (numeric ascending by default) and joined by dashes. Input Gamma(100)-Alpha(14)-Beta(42) comes back ordered Alpha(14)-Beta(42)-Gamma(100).
test{aggregate:sum:{ids:9e1d2b9f88e3d6c3bf0eb967378610d6:d-integer.........->-99}:_#NUMBER__}
Expected1355
Actual1355
The everyday pattern: feed a queried set straight into aggregate. {ids:...} returns the ids of items matching a condition, and sum totals a numeric field across them. Here the items whose integer is greater than 99 (Gamma 100, Theta 255, Kappa 1000) total 1355. This is how an order total or a price sum is built from a relation or search result.