web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

How to do aggregation in dynamics 365 (common data service) web api?

(0) ShareShare
ReportReport
Posted on by 37

Hi,

Is there any way to aggregate data (e.g. return average order value across all orders for a given customer) using the common data services web api, or do I have to retrieve each individual record and perform the aggregation in my code?

I have the same question (0)
  • Verified answer
    Alejandro Serdan Profile Picture
    on at

    Hi!

    Here is the information to do the aggregation:

    Aggregate and Grouping results

    docs.microsoft.com/.../query-data-web-api

    Regards.

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    You could create rollup field to get the aggregate value and use this field in webapi to show wherever you want.

    Please see below link to check how to setup rolup field in Dynamics CRM.

    https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/customize/define-rollup-fields

    If found helpful, Please mark my answer verified.

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Tim,

    You can aggregate data using Web API.

    You can refer to: 

    https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/query-data-web-api#aggregate-and-grouping-results

    Here are steps that follow your example (return average order value across all orders for a given customer).

    1.This is all orders.

    1348.png

    You can directly calculate average of all orders is 35354.3333. And the average is 20065.5 when the given customer named Jim Glynn(sample).

    2.using Web API.

    (1) calculate all orders.

    salesorders?$apply=aggregate(totalamount with average as averagevalue)

    8780.png

    (2) calculate orders that given customer named Jim Glynn(sample).

    salesorders?$apply=aggregate(totalamount with average as averagevalue) &$filter=_customerid_value eq '491a2f1a-628e-ea11-a811-000d3a35bad3'

    6507.png

    Regards,

    Clofly

  • Tim Robinson Profile Picture
    37 on at

    Thanks - I was looking under "Function" and "Query Function" in the web api reference which is why I didn't find it!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 70

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans