Showing results for 
Search instead for 
Did you mean: 
Post Prodigy
Post Prodigy

Count number of related CDS records

I have two custom entities in my CDS. One entity is Tracker, the other entity is Details. Details has a many to one relationship with Tracker. 


Tracker has a lookup named Facility(cr5be_facility), that does a lookup to the Facility Entity to pull the Facility name the tracker is about. 


Details has a lookup to Tracker, also named Facility(cr5be_facility), that does a lookup to the Tracker entity to pull the name the details are about.


I'm trying to create a flow, that when a new record is added to the Details entity, a field on the Tracker record it's connected to will be updated with a count of the number of records in the Details. This count should be based on an option set field on the Details record named Survey Outcome(cr5be_surveyoutcome).


So, for each choice in Survey Outcome on the Details record, I intend to have a count of the number of those Outcomes, on the related record in the Tracker entity. 


Hopefully I explained that clear enough someone can understand what I mean. 


I've tried to do a Flow that would compare the Facility fields, but it did not work. I assume it's because one of the Facility fields is a lookup to the Facility entity, where the other lookup is to the Tracker. While they have the same text value, it seems like the GUID is what's actually getting compared; which of course is different.


2020-01-28 14_33_22-Edit your flow _ Power Automate.png 

Super User III
Super User III


For lookup fields reference. Check out my solution on this post:

Note that in my example I am using Dynamics 364 connector. The same will be applied with the CDS connector.

If this does not help you, could you try and give some additional information.


If you like my post please hit the "Thumbs Up" -- If my post solved your issue please "Mark as a Solution" to help others

Did I answer your question? Mark my post as a solution!

If you like my post please hit the Thumbs Up

Proud to be a Flownaut!

Check out my blog for Power Automate tips,
tricks, and guides

Community Support
Community Support

Hi @notj ,


The expression to count the number of the records:





Best regards,



Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Post Prodigy
Post Prodigy

@Jcook I'll give that a look, thanks.


@v-alzhan-msft I don't think you understand what the issue is. It's not "how am I going to count them". It's the relational part.  Basically, all the stuff I described in the post.



Post Prodigy
Post Prodigy

@Jcook Unfortunately, I was right. While the labels are the same, the values are not. Both fields are named Facility, both are lookups, but one is on the parent (Trackers) entity, and the other is on another entity (All Facilities). So the GUID's don't match.


Is there any way to compare the displayed text values instead of the GUID?

Helpful resources

MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Top Solution Authors
Users online (1,132)