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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Getting a CountRows wi...
Power Apps
Unanswered

Getting a CountRows within 1 table for each item in a collection

(1) ShareShare
ReportReport
Posted on by 122

I have Dataverse tables that are separated by a few degrees relationship-wise, but need to be able to get a count of rows in one table for each item in a collection. Can I do a CountRows(Filter) call within a ForAll() function? I'm assuming this would not be the recommended approach for performance reasons, so what kind of pattern should I try to follow?

Categories:
I have the same question (1)
  • ivan_apps Profile Picture
    2,187 Moderator on at

    Are you trying to do anything else with the count on the related data or just display it in a gallery?

     

    you could put a text label on a gallery and do a Counts(Filter(your_table, this item.id=your relationship)) 

    this should display it on the gallery.

  • mhomol Profile Picture
    122 on at

    So I was trying to use the DetailsList component from CreatorKit, since it gives me more tabular functionality OOTB, but the gallery is an interesting call, so I may just have to try this out and see if that gets me where I want to be then might have to bite the bullet and build out some tabular functionality for a gallery instead.

  • Verified answer
    Static Profile Picture
    118 on at

    You can use CountRows(Filter()) within a ForAll() function in Power Apps, but you're right that this might not be optimal for performance, especially if you're dealing with large datasets. Each call to CountRows(Filter()) within ForAll() would result in multiple data retrieval operations, which can slow down your app.

     

    Load your data into collections to reduce multiple calls to Dataverse.

    ClearCollect(MyTable1Collection, MyTable1);
    ClearCollect(MyTable2Collection, MyTable2);

    Group and Count:
    Use GroupBy and AddColumns to create a summarized collection with counts.

    ClearCollect(
    SummaryCollection,
    AddColumns(
    GroupBy(MyTable1Collection, "GroupColumn", "GroupedItems"),
    "ItemCount",
    CountRows(Filter(MyTable2Collection, RelatedColumn in GroupedItems))
    )
    );

    Display the Summary:
    Now you can use SummaryCollection to display the counts or further process them.

    Gallery.Items = SummaryCollection

  • ivan_apps Profile Picture
    2,187 Moderator on at

    Yeah the creator kit is very nice looking but if I recall correctly it’s all JSON configuration so you may not be able to implement PowerFX within the details list config.

     

    another alternative is creating a rollup field in Dataverse. You can have it count all the sub-items and it should work with the caveat that it’s not an instant roll-up. It’s scheduled a couple of times a day so if you wanted and instant roll-up you’d have to implement it custom.

  • mhomol Profile Picture
    122 on at

    Thank you to everyone who responded.  I ended up following @statc 's guidance and loaded information into separate collections, where one of them had the grouping all setup and the other collection was able to simply read in the CountRows from the grouped collection.  So far, so good!

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard