Support for Field Types in Aggregate Functions

Using aggregate functions in SOQL queries is a powerful way to analyze records, but the functions aren’t relevant for all field types. For example, base64 fields don’t support aggregate functions because they wouldn’t generate any meaningful data.

Aggregate functions are supported for several primitive data types and field types. The following table lists support by the aggregate functions for the primitive data types.

Data TypeAVG()COUNT()COUNT_DISTINCT()MIN()MAX()SUM()
base64NoNoNoNoNoNo
booleanNoNoNoNoNoNo
byteNoNoNoNoNoNo
dateNoYesYesYesYesNo
dateTimeNoYesYesYesYesNo
doubleYesYesYesYesYesYes
intYesYesYesYesYesYes
stringNoYesYesYesYesNo
timeNoNoNoNoNoNo

In addition to the primitive data types, the API uses an extended set of field types for object fields. The following table lists support by the aggregate functions for these field types.

Data TypeAVG()COUNT()COUNT_DISTINCT()MIN()MAX()SUM()
addressNoNoNoNoNoNo
anyTypeNoNoNoNoNoNo
calculatedDepends on data type*Depends on data type*Depends on data type*Depends on data type*Depends on data type*Depends on data type*
comboboxNoYesYesYesYesNo
currency**YesYesYesYesYesYes
DataCategoryGroupReferenceNoYesYesYesYesNo
emailNoYesYesYesYesNo
encryptedstringNoNoNoNoNoNo
floatarrayNoNoNoNoNoNo
locationNoNoNoNoNoNo
IDNoYesYesYesYesNo
masterrecordNoYesYesYesYesNo
multipicklistNoNoNoNoNoNo
percentYesYesYesYesYesYes
phoneNoYesYesYesYesNo
picklistNoYesYesYesYesNo
referenceNoYesYesYesYesNo
textarea***NoYesYesYesYesNo
textarrayNoNoNoNoNoNo
urlNoYesYesYesYesNo

* Calculated fields are custom fields defined by a formula, which is an algorithm that derives its value from other fields, expressions, or values. Therefore, support for aggregate functions depends on the type of the calculated field.

** Aggregate function results on currency fields default to the system currency.

*** Text Area (Long) and Text Area (Rich) fields don’t support aggregate functions.

Some object fields have a field type that doesn’t support grouping. You can’t include fields with these field types in a GROUP BY clause.

Tip