Skip to main content
Dynamics 365 general forum
Answered

Filter on a amount of a related entity.

editSubscribe (0) ShareShare
ReportReport
Posted on by

I'm trying to get a report from customer filtered on related records for example, all customers which opened more then 100 cases during the last year, how can I achieve this, I tried with fetch-xml using aggregation since I wasen't able to filter on the aggregation, also note: both the customer and the related entity contains more than 5000 records.

Categories:
  • Verified answer
    Bipin D365 Profile Picture
    Bipin D365 28,934 Super User on at
    RE: Filter on a amount of a related entity.

    Hello,

    I'm glad that it worked.

    Could you please mark my answer verified by clicking Yes under 'Did this answer your question?'

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • salmy Profile Picture
    salmy on at
    RE: Filter on a amount of a related entity.

    Thanks for the answer, it worked like a charm, and BTW I learned a lot of new things from your blogs, it's amazing.

  • Verified answer
    Bipin D365 Profile Picture
    Bipin D365 28,934 Super User on at
    RE: Filter on a amount of a related entity.

    Hi,

    Have you tried creating a rollup field on Customer which will show count of Opened cases duing last year?

    Then use this filter in your fetchxml.

    Ohhh....We don't have option to filter Case records created during last year...

    I have tried writting below SQL code based on Account (OOB Entity) and Employee (Custom entity)-

    SELECT a.name FROM msft_employee
    
    INNER JOIN account AS a ON msft_employee.msft_company = a.accountid
    
    WHERE msft_employee.statecode = 0 AND msft_employee.createdon = lastxyears(1)
    
    group by a.name having COUNT(a.name)>=100

    I did try to see fetchxml with the help of SQL4CDS plugin in xrmtoolbox but it shows 3 fetchxml -

    markcarrington.dev/.../

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • salmy Profile Picture
    salmy on at
    RE: Filter on a amount of a related entity.

    Thanks for your response, I checked the link you posted, but I can't find how to filter on the amount of the retrieved records from the related records, as I wrote I only want to return the customers which had opened more than 100 cases in last year.

  • Verified answer
    mobeenmohsin Profile Picture
    mobeenmohsin on at
    RE: Filter on a amount of a related entity.

    Hi,

    Please find information to get large records using paging as mentioned in https://docs.microsoft.com/en-us/powerapps/developer/data-platform/org-service/page-large-result-sets-with-fetchxml.

    Best Regards,

    Mobeen

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,068 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,591 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans