集計関数 aggregation-functions

集計関数は、一連の値に対して計算を実行し、単一の集計結果を返します。 これらの関数を使用すると、平均値を計算したり、最小値と最大値を検索したり、要素をカウントしたり、数値を合計したりすることで、ジャーニー式内のデータを分析できます。

集計関数は、次の操作が必要な場合に使用します。

  • リストまたは配列から統計値を計算(avgsumminmax
  • null 値を含めるか除外するオプションを使用して、コレクション内の要素をカウント(countcountOnlyNullcountWithNull
  • データセット内の一意の値を決定(distinctCountdistinctCountWithNull
  • 計算指標に基づいてデータ駆動型の意思決定を実行

集計関数は、特定の動作に従って 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 を返します。

AI Knowledge Reference

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 min or max
  • Count non-null, null-only, or all elements in a list using count, countOnlyNull, or countWithNull
  • Count distinct values in a list, with or without nulls, using distinctCount or distinctCountWithNull
  • Filter unique objects in a listObject by a specific key attribute using distinctCount with 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, and distinctCountWithNull do not support the <listObject> parameter type
  • distinctCount on a listObject requires the list to be a field reference, not an inline literal
  • count on a listObject requires 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 avg include null values in its calculation? — No, avg ignores null values automatically.
  • Q: What is the difference between count and countWithNull?count excludes null values from the total, while countWithNull counts every element including nulls.
  • Q: Can I use countOnlyNull on a listObject? — No, <listObject> is not supported by countOnlyNull, countWithNull, or distinctCountWithNull.
  • 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 max return when the list contains nulls?max ignores null values and returns the maximum among the non-null elements.
recommendation-more-help
journey-optimizer-help