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

Announcements

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

fetchxml aggregate function

(0) ShareShare
ReportReport
Posted on by 2,510

Hi, I have aggregation function inside the link entity, it is returning total number of records, however, when the link entity has no value, there is no result returned, how can I make it return 0 when there is no value. Please advise, 


   
   

   
  

   

   
  
  

  
  

I have the same question (0)
  • Suggested answer
    ManoVerse Profile Picture
    539 Super User 2026 Season 1 on at
    If i understand correctly you want to collect how many records associated with your table ,  I am not able to see your fetch xml here but i hope you are using outer join for your link entity,  Below is working working fetch xml for me 
     
    <fetch aggregate="true">
        <entity name="account">
            <!-- group by the parent you want one row per parent -->
            <attribute name="accountid" alias="accountid" groupby="true"/>
            <attribute name="name" alias="accountname" groupby="true"/>
           <!-- (optional) parent-side filters -->
            <filter type="and">
                <condition attribute="statecode" operator="eq" value="0"/>
    <condition attribute="createdon" operator="on-or-after" value="2026-01-01"/>
                    <condition attribute="createdon" operator="on-or-before" value="2026-01-15"/>
               <!-- Active accounts -->
            </filter>
           <!-- LEFT OUTER JOIN so parents with no children are included -->
            <link-entity name="contact" from="parentcustomerid" to="accountid" link-type="outer" alias="c">
                <!-- countcolumn is key: returns 0 when no child rows on an outer join -->
                <attribute name="contactid" alias="contactcount" aggregate="countcolumn"/>
               <!-- Child-side filters (optional): e.g., only active contacts created in the slice -->
                <filter type="and">
                    <condition attribute="statecode" operator="eq" value="0"/>
                </filter>
            </link-entity>
        </entity>
    </fetch>
     
    result would be like this  

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 56 Super User 2026 Season 1

#2
Eugen Podkorytov Profile Picture

Eugen Podkorytov 49

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 44 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans