Saturday, 16 April 2016

Multiple group by - FetchXML Query

The following FetchXML shows how to use the aggregate attribute and multiple groupby clauses.
  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. <attribute name='actualclosedate' groupby='true' dategrouping='quarter' alias='quarter' />
  7. <attribute name='actualclosedate' groupby='true' dategrouping='year' alias='year' />
  8. <filter type='and'>
  9. <condition attribute='statecode' operator='eq' value='Won' />
  10. </filter>
  11. </entity>
  12. </fetch>
Explanation
To create multiple group by FetchXML query:
  • Set aggregate to true in fetch node.
    <fetch distinct='false' mapping='logical' aggregate='true'>
    
  • Add required aggregate attributes in entity clause.
    <attribute name='name' alias='opportunity_count' aggregate='count' />
    
  • Add multiple group by attributes by setting keyword groupby to true.
    <attribute name='actualclosedate' groupby='true' dategrouping='quarter' alias='quarter' />
    <attribute name='actualclosedate' groupby='true' dategrouping='year' alias='year' />
- See more at: http://msxrmtools.com/fetchxml/reference

No comments:

Post a Comment