AGG_AVG
Description
Performs a dynamic aggregation on a specified Salesforce object and returns the average of a selected numeric field from all records that match the given criteria.
Syntax
AGG_AVG(aggregate_object_name, aggregate_field_name, ...[group_field_name, group_field_value], additional_filters_optional) -> Decimal
Parameters
| Parameter | Data Type | Required | Description |
|---|---|---|---|
| aggregate_object_name | String | Yes | The name of the object containing data to aggregate. |
| aggregate_field_name | String | Yes | The name of the numeric field to average. |
| … group_field_name | String | No | The name of the field used for grouping records. |
| … group_field_value | Object | No | The field value used as grouping criteria. |
| additional_filters_optional | String | No | Additional filter conditions to apply. |
Examples
AGG_AVG(
"Opportunity",
"Amount",
"AccountId", Id,
"StageName = 'Closed Won'"
)
-- Returns the average Amount from Opportunity records grouped by AccountId, filtered by StageName = "Closed Won", where Opportunity.AccountId matches the Id from the source records.
-- At runtime, DSP generates the following SOQL query:
SELECT AccountId groupField0, AVG(Amount) agg0
FROM Opportunity
WHERE AccountId IN ('0018K00000kPuYXQA0', '0018K00000kPuYYQA0', '0018K00000kPuYZQA0', '0018K00000kPuYaQAK', '0018K00000kPuYbQAK') AND StageName = 'Closed Won'
GROUP BY AccountIdAGG_AVG(
"Opportunity",
"Amount",
"AccountId", Id,
"OwnerId", OwnerId,
"Type = 'New Business' AND CALENDAR_YEAR(CloseDate) = 2023"
)
-- Returns the average Amount from Opportunity records grouped by AccountId and OwnerId, filtered by Type = "New Business" and CloseDate in calendar year 2023, where Opportunity.AccountId and Opportunity.OwnerId match the corresponding values from the source records.
-- At runtime, DSP generates the following SOQL query:
SELECT AccountId groupField0, OwnerId groupField1, AVG(Amount) agg0
FROM Opportunity
WHERE (AccountId IN ('0018K00000kPuYXQA0', '0018K00000kPuYYQA0', '0018K00000kPuYZQA0', '0018K00000kPuYaQAK', '0018K00000kPuYbQAK') AND OwnerId IN ('005D2000006JY2bIAG', '0058K0000047WdvQAE', '0055e000007rpICAAY')) AND Type = 'New Business' AND CALENDAR_YEAR(CloseDate) = 2023
GROUP BY AccountId, OwnerIdRelated information
- DSP handles AGG_ functions efficiently. See AGGREGATE GENERAL for details.