集計関数 aggregation-functions
集計関数は、一連の値に対して計算を実行し、単一の集計結果を返します。 これらの関数を使用すると、平均値を計算したり、最小値と最大値を検索したり、要素をカウントしたり、数値を合計したりすることで、ジャーニー式内のデータを分析できます。
集計関数は、次の操作が必要な場合に使用します。
- リストまたは配列から統計値を計算(avg、sum、min、max)
- null 値を含めるか除外するオプションを使用して、コレクション内の要素をカウント(count、countOnlyNull、countWithNull)
- データセット内の一意の値を決定(distinctCount、distinctCountWithNull)
- 計算指標に基づいてデータ駆動型の意思決定を実行
集計関数は、特定の動作に従って null 値を自動的に処理するので、欠落値や未定義値が含まれる場合がある実際のデータの操作が容易になります。
avg avg
リストまたは 2 つの式のいずれかで指定された一連の式の平均値を返します。 null 値は無視されます。
avg(<parameter>)サポートされているタイプ:
- listInteger
- listDecimal
- 小数
- 整数
avg(<listInteger>)
avg(<listDecimal>)
avg(<decimal>,<decimal>)
avg(<decimal>,<integer>)
avg(<integer>,<decimal>)
avg(<integer>,<integer>)
小数を返します。
avg(@event{BarBeacon.inventory},5)
avg([10,3,8])
7.0 を返します。
avg(10.2, 3)
6.6 を返します。
count count
null 値を数に入れずに、リストの要素数を数えます。
count(<listAny>)
count(<listObject>)
| table 0-row-3 1-row-3 | ||
|---|---|---|
| パラメーター | タイプ | 説明 |
| listToProcess | listString、listBoolean、listInteger、listDecimal、listDuration、listDateTime、listDateTimeOnly、listDateOnly、listObject のいずれか | 処理するリスト。 listObject の場合は、フィールド参照にする必要があります。 listObject に null オブジェクトを含めることはできません。 |
count(<listAny>)
整数を返します。
count([10,2,10,null])
3 を返します。
count(@event{my_event.productListItems})
指定されたオブジェクト配列内のオブジェクト数を返します(listObject 型)。 注:listObject に null オブジェクトを含めることはできません
countOnlyNull countOnlyNull
リスト内の null 値の数をカウントします。
countOnlyNull(<listAny>)| table 0-row-2 1-row-2 | |
|---|---|
| パラメーター | タイプ |
| listToProcess | listString、listBoolean、listInteger、listDecimal、listDuration、listDateTime、listDateTimeOnly、listDateOnly |
countOnlyNull(<listAny>)
整数を返します。
countOnlyNull([10,2,10,null])
1 を返します。
メモ:パラメーター <listObject> は、この関数ではサポートされません。
countWithNull countWithNull
null 値を含むリストのすべての要素をカウントします。
countWithNull(<listAny>)| table 0-row-2 1-row-2 | |
|---|---|
| パラメーター | タイプ |
| listToProcess | listString、listBoolean、listInteger、listDecimal、listDuration、listDateTime、listDateTimeOnly、listDateOnly |
countWithNull(<listAny>)
整数を返します。
countWithNull([10,2,10,null])
4 を返します。
メモ:パラメーター <listObject> は、この関数ではサポートされません。
distinctCount distinctCount
null 値を無視して異なる値の数をカウントします。
distinctCount(<listAny>)| table 0-row-3 1-row-3 2-row-3 | ||
|---|---|---|
| パラメーター | タイプ | 説明 |
| listToProcess | listString、listBoolean、listInteger、listDecimal、listDuration、listDateTime、listDateTimeOnly、listDateOnly、listObject のいずれか | 処理するリスト。 listObject の場合は、フィールド参照にする必要があります。 |
| keyAttributeName | 文字列 | このパラメーターはオプションで、listObject に対してのみ使用できます。 パラメーターを指定しないと、すべての属性の値が同じ場合、オブジェクトは重複していると見なされます。 パラメーターを指定していて、指定された属性が同じ値を持つ場合、オブジェクトは重複していると見なされます。 |
distinctCount(<listAny>)
整数を返します。
distinctCount(<listObject>)
distinctCount(<listObject>,<string>)
オブジェクトのリストを返します。
distinctCount([10,2,10,null])
2 を返します。
distinctCount(@event{my_event.productListItems})
指定されたオブジェクト配列内の厳密に異なるオブジェクトの数を返します(listObject 型)。
distinctCount(@event{my_event.productListItems}, "SKU")
個別の「SKU」属性値 {} を持つオブジェクトの数を返します。
distinctCountWithNull distinctCountWithNull
null 値を含め、異なる値の数をカウントします。
distinctCountWithNull(<listAny>)| table 0-row-2 1-row-2 | |
|---|---|
| パラメーター | タイプ |
| listToProcess | listString、listBoolean、listInteger、listDecimal、listDuration、listDateTime、listDateTimeOnly、listDateOnly |
distinctCountWithNull(<listAny>)
整数を返します。
distinctCountWithNull([10,2,10,null])
3 を返します。
メモ:パラメーター <listObject> は、この関数ではサポートされません。
max max
リストまたは 2 つの式として指定された一連の式の中から最大値を返します。 null 値は無視されます。
max(<parameter>)- listDuration
- listInteger
- listDecimal
- listDateTime
- listDateTimeOnly
- listDateOnly
- 期間
- 整数
- 小数
- 日時
- dateTimeOnly
max(<listDuration>)
期間を返します。
max(<listInteger>)
期間を返します。
max(<listDateTimeOnly>)
タイムゾーンを無視して日時を返します。
max(<listDateTime>)
日時を返します。
max(<listDateOnly>)
日付を返します。
max(<listDecimal>)
小数を返します。
max(<decimal>,<decimal>)
小数を返します。
max(<duration>,<duration>)
期間を返します。
max(<dateTime>,<dateTime>)
日時を返します。
max(<dateTimeOnly>,<dateTimeOnly>)
タイムゾーンを無視して日時を返します。
max(<integer>,<integer>)
整数を返します。
max(@event{BarBeacon.inventory},5)
max([10,3,8])
10 を返します。
max([10,null,8])
10 を返します。
min min
リストまたは 2 つの式のいずれかで指定された一連の式の中の最小値を返します。 null 値は無視されます。
min(<parameters>)- listDuration
- listInteger
- listDecimal
- listDateTime
- listDateTimeOnly
- listDateOnly
- 期間
- 整数
- 小数
- 日時
- dateTimeOnly
min(<listDuration>)
期間を返します。
min(<listInteger>)
期間を返します。
min(<listDateTimeOnly>)
タイムゾーンを無視して日時を返します。
min(<listDateTime>)
日時を返します。
min(<listDateOnly>)
日付を返します。
min(<listDecimal>)
小数を返します。
min(<decimal>,<decimal>)
小数を返します。
min(<duration>,<duration>)
期間を返します。
min(<dateTime>,<dateTime>)
日時を返します。
min(<dateTimeOnly>,<dateTimeOnly>)
タイムゾーンを無視して日時を返します。
min(<integer>,<integer>)
整数を返します。
min(@event{BarBeacon.inventory},5)
min([10,3,8])
3 を返します。
min([10,null,8])
8 を返します。
sum sum
一連の式の値の合計を返します。 null 値は無視されます。
sum(<parameters>)- listInteger
- listDecimal
- 期間
- 整数
- 小数
sum(<listDecimal>)
小数を返します。
sum(<listInteger>)
整数を返します。
sum(<integer>,<integer>)
整数を返します。
sum(<decimal>,<decimal>)
小数を返します。
sum(@event{BarBeacon.inventory},5)
sum([10,3,8])
21 を返します。
sum([10.5,null,8.1])
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.