Search code examples
dynamics-crmodatadynamics-crm-onlinedynamics-crm-webapi

MS CRM Online: Get all accounts with more than X contacts


Is it possible to get all accounts in MS CRM Online with more than X contacts via odata (this is probably not possible via FetchXML)?

Something like (dummy code, does not work):

accounts?$apply=aggregate(contact_customer_accounts with countdistinct as total)/filter(total gt X)

Solution

  • Unfortunately, this is not possible as it is not straight forward with a single query using fetchxml (no support for subquery and aggregation with having clause) or web api. You can pull all the results and do aggregation using LINQ or other ways.

    Compared to that, using a single rollup attribute to count the child contact records on parent account (not a calculated field) is the easiest option.