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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

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,189 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,189 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 530

#2
WarrenBelz Profile Picture

WarrenBelz 459 Most Valuable Professional

#3
Haque Profile Picture

Haque 314

Last 30 days Overall leaderboard