Funciones de agregación aggregation-functions
Las funciones de agregación realizan cálculos en un conjunto de valores y devuelven un único resultado resumido. Estas funciones permiten analizar los datos dentro de las expresiones de recorrido calculando promedios, buscando valores mínimos y máximos, contando elementos y sumando valores numéricos.
Utilice funciones de agregación cuando necesite:
- Calcular valores estadísticos de listas o matrices (avg, sum, min, max)
- Contar elementos en colecciones (count, countOnlyNull, countWithNull), con opciones para incluir o excluir valores nulos
- Determinar valores únicos dentro de conjuntos de datos (distinctCount, distinctCountWithNull)
- Tome decisiones basadas en datos y en métricas calculadas
Las funciones de agregación administran automáticamente los valores nulos según su comportamiento específico, lo que facilita el trabajo con datos del mundo real que pueden contener valores que faltan o indefinidos.
avg avg
Devuelve el valor promedio entre un conjunto de expresiones, dado como una lista o dos expresiones. Los valores nulos se omiten.
avg(<parameter>)Tipos admitidos:
- listInteger
- listDecimal
- decimal
- entero
avg(<listInteger>)
avg(<listDecimal>)
avg(<decimal>,<decimal>)
avg(<decimal>,<integer>)
avg(<integer>,<decimal>)
avg(<integer>,<integer>)
Devuelve un valor decimal.
avg(@event{BarBeacon.inventory},5)
avg([10,3,8])
Devuelve 7.0.
avg(10.2, 3)
Devuelve 6.6.
recuento count
Cuenta los elementos de la lista que no tienen en cuenta los valores nulos.
count(<listAny>)
count(<listObject>)
| table 0-row-3 1-row-3 | ||
|---|---|---|
| Parámetro | Tipo | Descripción |
| listToProcess | listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly o listObject | Lista para procesar. Para listObject, debe ser una referencia de campo. Un listObject no puede contener un objeto nulo. |
count(<listAny>)
Devuelve un entero.
count([10,2,10,null])
Devuelve 3.
count(@event{my_event.productListItems})
Devuelve el número de objetos de una matriz determinada de objetos (tipo listObject). Nota: un listObject no puede contener un objeto nulo
countOnlyNull countOnlyNull
Cuenta el número de valores nulos de la lista.
countOnlyNull(<listAny>)| table 0-row-2 1-row-2 | |
|---|---|
| Parámetro | Tipo |
| listToProcess | listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly |
countOnlyNull(<listAny>)
Devuelve un entero.
countOnlyNull([10,2,10,null])
Devuelve 1.
Nota: El parámetro <listObject> no se admite en esta función.
countWithNull countWithNull
Cuenta todos los elementos de la lista, incluidos los valores nulos.
countWithNull(<listAny>)| table 0-row-2 1-row-2 | |
|---|---|
| Parámetro | Tipo |
| listToProcess | listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly |
countWithNull(<listAny>)
Devuelve un entero.
countWithNull([10,2,10,null])
Devuelve 4.
Nota: El parámetro <listObject> no se admite en esta función.
distinctCount distinctCount
Cuenta el número de valores diferentes e ignora los valores nulos.
distinctCount(<listAny>)| table 0-row-3 1-row-3 2-row-3 | ||
|---|---|---|
| Parámetro | Tipo | Descripción |
| listToProcess | listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly o listObject | Lista para procesar. Para listObject, debe ser una referencia de campo. |
| keyAttributeName | cadena | Este parámetro es opcional y solo para listObject. Si no se proporciona el parámetro, un objeto se considera duplicado si todos los atributos tienen los mismos valores. De lo contrario, un objeto se considera duplicado si el atributo dado tiene el mismo valor. |
distinctCount(<listAny>)
Devuelve un entero.
distinctCount(<listObject>)
distinctCount(<listObject>,<string>)
Devuelve una lista de objetos.
distinctCount([10,2,10,null])
Devuelve 2.
distinctCount(@event{my_event.productListItems})
Devuelve el número de objetos estrictamente distintos en la matriz de objetos determinada (tipo listObject).
distinctCount(@event{my_event.productListItems}, "SKU")
Devuelve el número de objetos que tienen un valor de atributo “SKU” distinto {}.
distinctCountWithNull distinctCountWithNull
Cuenta el número de valores diferentes, incluidos los valores nulos.
distinctCountWithNull(<listAny>)| table 0-row-2 1-row-2 | |
|---|---|
| Parámetro | Tipo |
| listToProcess | listString, listBoolean, listInteger, listDecimal, listDuration, listDateTime, listDateTimeOnly, listDateOnly |
distinctCountWithNull(<listAny>)
Devuelve un entero.
distinctCountWithNull([10,2,10,null])
Devuelve 3.
Nota: El parámetro <listObject> no se admite en esta función.
max max
Devuelve el valor máximo entre un conjunto de expresiones, dado como una lista o dos expresiones. Los valores nulos se omiten.
max(<parameter>)- listDuration
- listInteger
- listDecimal
- listDateTime
- listDateTimeOnly
- listDateOnly
- duration
- entero
- decimal
- dateTime
- dateTimeOnly
max(<listDuration>)
Devuelve una duración.
max(<listInteger>)
Devuelve una duración.
max(<listDateTimeOnly>)
Devuelve una fecha y hora sin considerar la zona horaria.
max(<listDateTime>)
Devuelve una fecha y hora.
max(<listDateOnly>)
Devuelve una fecha.
max(<listDecimal>)
Devuelve un valor decimal.
max(<decimal>,<decimal>)
Devuelve un valor decimal.
max(<duration>,<duration>)
Devuelve una duración.
max(<dateTime>,<dateTime>)
Devuelve una fecha y hora.
max(<dateTimeOnly>,<dateTimeOnly>)
Devuelve una fecha y hora sin considerar la zona horaria.
max(<integer>,<integer>)
Devuelve un entero.
max(@event{BarBeacon.inventory},5)
max([10,3,8])
Devuelve 10.
max([10,null,8])
Devuelve 10.
min min
Devuelve el valor mínimo entre un conjunto de expresiones, dado como una lista o dos expresiones. Los valores nulos se omiten.
min(<parameters>)- listDuration
- listInteger
- listDecimal
- listDateTime
- listDateTimeOnly
- listDateOnly
- duration
- entero
- decimal
- dateTime
- dateTimeOnly
min(<listDuration>)
Devuelve una duración.
min(<listInteger>)
Devuelve una duración.
min(<listDateTimeOnly>)
Devuelve una fecha y hora sin considerar la zona horaria.
min(<listDateTime>)
Devuelve una fecha y hora.
min(<listDateOnly>)
Devuelve una fecha.
min(<listDecimal>)
Devuelve un valor decimal.
min(<decimal>,<decimal>)
Devuelve un valor decimal.
min(<duration>,<duration>)
Devuelve una duración.
min(<dateTime>,<dateTime>)
Devuelve una fecha y hora.
min(<dateTimeOnly>,<dateTimeOnly>)
Devuelve una fecha y hora sin considerar la zona horaria.
min(<integer>,<integer>)
Devuelve un entero.
min(@event{BarBeacon.inventory},5)
min([10,3,8])
Devuelve 3.
min([10,null,8])
Devuelve 8.
sum sum
Devuelve la suma de los valores de un conjunto de expresiones. Los valores nulos se omiten.
sum(<parameters>)- listInteger
- listDecimal
- duration
- entero
- decimal
sum(<listDecimal>)
Devuelve un valor decimal.
sum(<listInteger>)
Devuelve un entero.
sum(<integer>,<integer>)
Devuelve un entero.
sum(<decimal>,<decimal>)
Devuelve un valor decimal.
sum(@event{BarBeacon.inventory},5)
sum([10,3,8])
Devuelve 21.
sum([10.5,null,8.1])
Devuelve 18.6.
This section contains structured knowledge intended to support interpretation, retrieval, and question answering related to this topic.
For complete understanding, this information should be combined with the documentation on this page. Neither source is intended to stand alone; the page describes the feature, while this section provides additional context that helps disambiguate terminology, intent, applicability, and constraints.
- TL;DR: This page documents all aggregation functions available in AJO journey expressions, covering how to compute averages, sums, min/max values, counts, and distinct counts over lists and arrays.
Intents:
- Calculate the average of a list of numeric values using
avg - Sum numeric values in a list or from event fields using
sum - Find the minimum or maximum value in a list using
minormax - Count non-null, null-only, or all elements in a list using
count,countOnlyNull, orcountWithNull - Count distinct values in a list, with or without nulls, using
distinctCountordistinctCountWithNull - Filter unique objects in a listObject by a specific key attribute using
distinctCountwith a key parameter
Glossary:
- listObject: A list of complex objects (field references); cannot contain null objects (product-specific)
- listAny: A list of any supported scalar type (string, boolean, integer, decimal, duration, dateTime, dateTimeOnly, dateOnly) (product-specific)
- Null value: An absent or undefined element in a list; most aggregation functions ignore nulls unless the function explicitly handles them (e.g.,
countOnlyNull,countWithNull,distinctCountWithNull)
Guardrails:
countOnlyNull,countWithNull, anddistinctCountWithNulldo not support the<listObject>parameter typedistinctCounton alistObjectrequires the list to be a field reference, not an inline literalcounton alistObjectrequires the list to be a field reference; a listObject cannot contain null objects
Terminology:
- Canonical name: Aggregation functions — Acronym: none — variants: aggregate functions, collection functions
- Synonyms: “count” = “count non-null elements”; “countWithNull” = “count all elements including nulls”
- Do not confuse: “distinctCount” (ignores nulls) ≠ “distinctCountWithNull” (includes nulls as a distinct value)
FAQ:
- Q: Does
avginclude null values in its calculation? — No,avgignores null values automatically. - Q: What is the difference between
countandcountWithNull? —countexcludes null values from the total, whilecountWithNullcounts every element including nulls. - Q: Can I use
countOnlyNullon a listObject? — No,<listObject>is not supported bycountOnlyNull,countWithNull, ordistinctCountWithNull. - Q: How do I count distinct objects in an array based on a specific attribute? — Use
distinctCount(@event{...}, "attributeName")providing the key attribute name as the second parameter. - Q: What does
maxreturn when the list contains nulls? —maxignores null values and returns the maximum among the non-null elements.