Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Nested Fetch Xml aggregates

Posted on by Microsoft Employee

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

  • Verified answer
    David Jennaway Profile Picture
    David Jennaway 14,063 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans