Power Apps

Count The Rows In A Power Apps Gallery With AllItemsCount

Count The Rows In A Power Apps Gallery With AllItemsCount Posted by - Matthew Devaney on - May 28, 2023 12 Comments There’s a better way to count the number ...

Matthew Devaney
Published
Reading time
3 min read

Before you start

Is this guide for you?

Best entry point
Power Apps
Time investment
3 min read

Imported reference from Matthew Devaney's blog for learning purposes. Original: https://www.matthewdevaney.com/count-the-rows-in-a-power-apps-gallery-with-allitemscount/. Author: Matthew Devaney.

Count The Rows In A Power Apps Gallery With AllItemsCount Posted by - Matthew Devaney on - May 28, 2023 12 Comments

There’s a better way to count the number of rows in a Power Apps gallery than the CountRows function.. The new AllItemsCount property allows us to easily get the row count. It also offers better performance than CountRows. In this article I’ll show you how to use a gallery’s AllItemsCount property. Table of Contents

Determine The Number Of Rows In A Gallery Using AllItemsCount Show The Gallery Row Count In A Label

Count Rows For A Gallery Datasource Over 100 Records

Determine The Number Of Rows In A Gallery Using AllItemsCount

We can use the AllItemsCount property to count the number of rows in a gallery. Power Apps must be version 3.23051.19 or newer to use this property. Gallery .AllItemsCount Code language: CSS ( css ) Show The Gallery Row Count In A Label

Let’s see what happens when we use AllItemsCount in an app. Open any app with a gallery . The example below shows a gallery with a list of products. Insert a new label above the gallery.

Write this code in the Text property of the label to display the number of rows. $ "{gal_Inventory.AllItemsCount} Items" Code language: JavaScript ( javascript )

Count Rows For A Gallery Datasource Over 100 Records

When the datasource used in a gallery’s Items property is over 100 records the gallery only loads the first 100 records until the user scrolls to the bottom. Then it loads records 101 to 200 and continues with this behavior until the last row is reached.

The example below shows a gallery datasource which has 1,000 records. Notice that the label showing the gallery’s row cost is incorrect.

When the user scrolls to the bottom of the gallery the next 100 rows appear. The gallery row count is now higher, but it is still wrong.

To fix this issue, we must write some new logic into our row count label. We want to show a + symbol when the gallery row count is unknown.

This code Sorts the gallery’s datasource in descending order to get the ID of the last row. Then if the last row does not appear at the bottom of the gallery then a + symbol is shown.

$ "{gal_Inventory.AllItemsCount}{If( First( Sort( 'Car Sales Inventory', ID, SortOrder.Descending ) ).ID <> Last(gal_Inventory.AllItems).ID, " + " )} Items" Code language: PHP ( php )

Now we can see the gallery has 1000 items when the user scrolls all the way to the bottom. Did You Enjoy This Article? 😺

Subscribe to get new Copilot Studio articles sent to your inbox each week for FREE Enter your email address Sign Me Up Questions?

If you have any questions or feedback about Count The Rows In A Power Apps Gallery With AllItemsCount please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion. Matthew Devaney M365 Copilot Power Apps

How To Create Copilot Custom UI Widgets In Power Apps

Share this

Tagged

Gallery · Power Apps

Have a Microsoft 365 topic idea?

Share article suggestions, community session ideas, corrections, or real-world scenarios for future nxtM365 learning notes.

Suggest a topic

Keep learning Microsoft 365

Explore more practical guides for SharePoint, Power Platform, Copilot Studio, migration, automation, governance, and security.

Continue learning

Next action

What to do next

Browse all tutorials →