Saturday, 16 April 2016

Multiple Aggregates - FetchXML Query

Multiple aggregates can be computed in a single FetchXML query.
Following FetchXML calculates count, sum and avg from opportunity entity.
  1. <fetch distinct='false' mapping='logical' aggregate='true'>
  2. <entity name='opportunity'>
  3. <attribute name='opportunityid' alias='opportunity_count' aggregate='count'/>
  4. <attribute name='estimatedvalue' alias='estimatedvalue_sum' aggregate='sum'/>
  5. <attribute name='estimatedvalue' alias='estimatedvalue_avg' aggregate='avg'/>
  6. </entity>
  7. </fetch>
Explanation
To calculate multiple aggregate in single FetchXML query
  • Set aggregate to true in fetch node.
  • For each type of aggregate add separate aggregate attribute and set aggregate value accordingly.
- See more at: http://msxrmtools.com/fetchxml/reference

No comments:

Post a Comment