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