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

Announcements

No record found.

News and Announcements icon
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
    Microsoft Employee 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,985 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 60 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 43

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans