Aggregate Functions

Data 360 Query Guide, mirrored from developer.salesforce.com: **Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API

markdownreferencev1NQJH-BKH6guide: data-cloud-query-guidestage: referencetrust: officialsource: developer.salesforce.comservice: data360interface: sqlAggregate FunctionsData 360Data CloudData 360 Query Guide

Created 23 Oct 2026 · Modified 23 Oct 2026 · 1 version

Mirror of <https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/aggregate.html> (Salesforce, Data 360 Query Guide), read 2026-10-23. Salesforce's own page is the authority; this copy exists because that site refuses non-browser readers.

Aggregate Functions

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Functions that compute a single result from a set of input values. Use aggregate functions to:

  • Summarize data by computing counts, sums, and averages.
  • Analyze distributions with statistical functions such as standard deviation and variance.
  • Find extremes with MIN and MAX values.
  • Compute percentiles and identify modes in datasets.
  • Collect values into an array, a delimited string, or a JSON array.
  • Null handling: Except for COUNT, ARRAY_AGG and JSON_ARRAYAGG, aggregate functions return NULL when no rows match. Use coalesce(aggregate_func(...), default_value) to substitute a default value.
  • Group by requirement: Non-aggregated fields in the SELECT clause must appear in the GROUP BY clause.
  • Filter clause: Use the FILTER clause to apply conditions to individual aggregates.

Common aggregate functions for summarizing data:

  • ANY_VALUE - Return an arbitrary value from the group.
  • APPROX_COUNT_DISTINCT - Compute an approximate count of distinct values.
  • AVG - Calculate the arithmetic mean.
  • BIT_AND - Compute bitwise AND of all values.
  • BIT_OR - Compute bitwise OR of all values.
  • BOOL_AND - Return true if all values are true.
  • BOOL_OR - Return true if any value is true.
  • COUNT - Count rows or non-null values.
  • MAX - Find the maximum value.
  • MAX_BY - Return the value from the row with the maximum key.
  • MIN - Find the minimum value.
  • MIN_BY - Return the value from the row with the minimum key.
  • SUM - Calculate the total.

Functions for statistical analysis:

Cast the input of an aggregate function to force a different output type. For example, use var_pop(CAST(A AS DOUBLE PRECISION)) to get a double precision result.

Functions that combine values from a group into a single array, string, or JSON array:

  • ARRAY_AGG - Collect values into an array, with optional ordering and NULL handling.
  • JSON_ARRAYAGG - Collect values into a JSON array, with optional ordering and NULL handling.
  • LISTAGG - Concatenate values into a single delimited string.

Aggregate functions that use the WITHIN GROUP syntax:

  • FIRST_VALUE - Return the <value> from the first row within each GROUP BY group after ordering by specified keys.
  • MODE - Return the most frequent value.
  • PERCENTILE_CONT - Compute continuous percentile with interpolation.
  • PERCENTILE_DISC - Compute discrete percentile without interpolation.

For MODE, PERCENTILE_CONT, and PERCENTILE_DISC, NULL values in the sorted input are ignored where noted on each function page. Percentile functions require a fraction between 0 and 1. FIRST_VALUE does not use a fraction. Ordering follows the ORDER BY keys and NULLS FIRST / NULLS LAST modifiers.

  • GROUPING - Identify which columns are aggregated in grouping sets.
  • FILTER Clause - Filter rows passed to aggregate functions.

Calculate summary statistics.

Summarize data by category.

Compute multiple filtered aggregates in one query.

Compute standard deviation and variance.

Find median and quartiles.

Read this document as markdown — the same bytes an agent receives.