Efficiently Count Gallery Rows in Power Apps: The AllItemsCount Property
Learn how to use the AllItemsCount property for fast, client-side row counting and how to handle large datasets properly.
Displaying the number of items inside a gallery is a common requirement in canvas apps. Many makers reach for the CountRows function, but it can introduce delegation issues and unnecessary network calls. The gallery’s built-in AllItemsCount property provides a faster, client‑side way to get the count of records currently loaded in the gallery. In this article we’ll explore how to use it, when it shines, and how to work around its limitations when dealing with large datasources.
Understanding AllItemsCount
AllItemsCount is a property available on any gallery control (vertical, horizontal, flexible height, etc.) that returns the number of items the gallery has loaded into memory. It doesn’t re‑query the datasource; it simply reads an internal counter that Power Apps maintains as the gallery renders.
This property is available from Power Apps version 3.23051.19 or later. Check your environment’s version before using it in production.
Scenario: Task Manager Dashboard
Imagine a task management app connected to a SharePoint list called Tasks. The list contains thousands of items, and you want a gallery to display active tasks. A label above the gallery should show something like “Showing 20 of 150 tasks” or simply “20 tasks” when the list is fully loaded.
To avoid confusion, we’ll use the following controls:
- Gallery:
gal_TaskList(bound to theTaskslist) - Label:
lbl_TaskCount(placed above the gallery)
Step‑by‑Step Implementation
1. Connect the Gallery
Set the gallery’s Items property to the datasource and apply any filter you need.
Filter(Tasks, Status = "Active")
2. Use AllItemsCount in a Label
For a basic count of visible items, set the label’s Text property:
"Tasks: " & gal_TaskList.AllItemsCount
The label will update automatically as the gallery loads more items during scrolling.
3. Combine with Total Count (When Delegation Works)
If your datasource supports delegation for CountRows, you can show both the loaded count and the total:
$"Showing {gal_TaskList.AllItemsCount} of {CountRows(Tasks)} tasks"Be careful: CountRows(Tasks) may not be delegated for some connectors (e.g., SharePoint), causing it to return only the first 500 items. In that case the total shown will be inaccurate.
Handling Large Datasources That Paginate
For non‑delegable datasources (or when CountRows can’t return the real total), the gallery only loads a chunk of records—often 100 at a time. AllItemsCount reflects only the loaded chunk, not the total dataset.
To indicate that more records exist, you can compare the last item’s ID in the gallery with the maximum ID in the datasource. If they differ, append a “+” to the count.
$"{gal_TaskList.AllItemsCount}" & If(
Not IsEmpty(gal_TaskList.AllItems),
If(
First(Sort(Tasks, "ID", SortOrder.Descending)).ID <> Last(gal_TaskList.AllItems).ID,
"+",
""
),
""
) & " tasks"How it works:
First(Sort(Tasks, "ID", SortOrder.Descending))gets the highestIDfrom the datasource.Last(gal_TaskList.AllItems).IDgets theIDof the last item currently in the gallery.- If they don’t match, there are more records to load, so
"+"is added.
When the user scrolls to the bottom and the gallery loads all records, the IDs will match and the label shows the exact total.
Using First(Sort(...)) and Last(...) in this way involves additional queries. For very large lists, consider storing the total count in a separate collection that you refresh less frequently.
Performance Benefits of AllItemsCount
- No extra network request – The count is read from memory, not from the datasource.
- No delegation risk –
AllItemsCountis always accurate for what the gallery has loaded. - Works with filters – If the gallery’s
Itemsincludes a filter or search, the count reflects only the filtered set. - Instant updates – When the gallery changes (pagination, filtering, sorting), the property updates synchronously.
Common Mistakes and Troubleshooting
| Mistake | Solution |
|---|---|
Using AllItemsCount on a non‑gallery control | Only galleries expose this property. |
| Expecting it to return the total dataset count | It returns only the currently loaded items. Use the workaround above if you need to hint at a larger dataset. |
| Forgetting the version requirement | If you see no property in IntelliSense, update your Power Apps environment. |
| Trying to set the property (read‑only) | AllItemsCount can only be read, never written. |
Basing logic on AllItemsCount when the gallery is empty | Check IsEmpty(gal.AllItems) first to avoid errors on Last(...). |
Final Recommendation
Use AllItemsCount whenever you need to display the number of items that a gallery is currently showing. It’s faster and simpler than CountRows(gal.AllItems) and avoids delegation pitfalls. For scenarios where you must also indicate unloaded records, combine the property with a lightweight check such as the ID‑matching pattern shown above.
Adopting this approach makes your apps more performant and your code easier to maintain.
References
- Original article by Matthew Devaney: Count The Rows In A Power Apps Gallery With AllItemsCount
- Microsoft Learn: Gallery control overview (update with exact URL if known)
- Microsoft Learn: CountRows function delegation notes (update with exact URL if known)
Learn how small coding practices—like using descriptive names, flattening conditions, and simplifying logic—can make your apps easier to update and less error-prone.
Move past the gallery and discover the hidden patterns for validation, navigation, and smart submission handling in your data entry forms.
PowerShell unlocks admin capabilities that the Power Platform admin center simply doesn’t offer—from recovering deleted apps to blocking trial licenses. Here’s how to wield them safely.