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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Nested Fetch Xml aggregates

(0) ShareShare
ReportReport
Posted on by

So I want to get the top 3 of the sum of values grouped by personid. So how do I set up the xml to support the nested aggregate?

<fetch top="50" aggregate="true" >
   <entity name="elcn_contributiondonor" >
        <attribute name="amount" alias="amount" aggregate="sum" />

        <attribute name='personid' alias='personid' groupby='true' />

   </entity>
</fetch>

Does the sum of every grouped by personId I believe but where do I put a second statement to get the top 3 of these sums?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    David Jennaway Profile Picture
    14,065 on at
    RE: Nested Fetch Xml aggregates

    You should be able to do this by sorting the results by the aggregate, and using the top attribute:

    <fetch aggregate="true" top="3" >
       <entity name="elcn_contributiondonor" >
            <attribute name="amount" alias="amount" aggregate="sum" />
            <attribute name='personid' alias='personid' groupby='true' />
    	<order alias='amount' descending='true' />
       </entity>
    </fetch>


    Alternatively you could use paging to get the first 3 records, instead of top

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans