Aggregate Your Results
AVAILABLE API VERSION |
---|
API v59.0 and later |
Analyze your results by using aggregate functions like finding the average, maximum, minimum, and sum.
To find the average amount and sum of all opportunities, send an aggregate function using the avg
and sum
functions.
The wire adapter returns a JSON response that looks like this.
The data returned from the GraphQL wire adapter has the same structure as the GraphQL query. While this structure works fine for programmatic use, it can be difficult to consume inside your component’s template. This line of code in the example removes extra layers in the response data to make it easier to consume in the template.
Your component then renders the results using the for:each
directive with aggregate
as the key.
This example uses the lightning-badge
base component to display the aggregate values.
Grouping summarizes your data based on a particular field. You can use aggregate functions with a groupBy
argument with optional types CUBE
or ROLLUP
.
Let's say you want to group account by year and get the count for each.
The wire adapter returns a JSON response that looks like this.
This example uses the lightning-badge
base component to display the aggregate values.