Live training: next batches coming soon. Join the waitlist:Waitlists open:Developer Training →Developer →Copilot Studio Training →Copilot Studio →

Power Apps Gallery Row Number [3 Various Ways]

While working on a Power Apps gallery to show a list of items, I wanted to add a row number to each record. This helps make the list look more organized and makes it easier to find and refer to specific items.

In this tutorial, I will explain how to add a Power Apps gallery row number dynamically and add a Power Apps gallery row number using a SharePoint list.

Additionally, we will explore how to generate row numbers for a Power Apps collection, providing examples.

So let’s get started!

Add Row Number to Gallery Dynamically in Power Apps

A Power Apps gallery can display a row number, which is simply a sequential number that increments for each item in the list. This number is automatically generated based on the number of items in the gallery.

As you can see in the GIF below, the Row Number has been generated dynamically in the Power Apps gallery. By default, all products will display a specific auto-incrementing number (1, 2, 3, and so on).

Additionally, whenever a user searches for a product, the specific filter list will appear with a dynamically generated number in the gallery.

Power Apps Gallery Row Number
  1. To achieve this, set up a SharePoint list, such as Sales Data, that contains various columns like:
ColumnData type
Product NameSingle line of text
Product CategorySingle line of text
Sales AmountCurrency
DateDate time
powerapps gallery row number
  1. Next, select the gallery and set its Items property to the code below:
With(
    {
        prodCountRow: Filter(
            'Sales Data',
            StartsWith(
                'Product Name',
                txtSearchProduct.Value
            )
        )
    },
    ForAll(
        Sequence(CountRows(prodCountRow)),
        Patch(
            Last(
                FirstN(
                    prodCountRow,
                    ThisRecord.Value
                )
            ),
            {ProdRowNumber: Value}
        )
    )
)

Where,

  • prodCountRow = Scope variable name
  • ‘Sales Data’ = SharePoint list name
  • ‘Product Name’ = Specify the column name that you want to search in the search box
  • txtSearchProduct = Text input name
powerapps get index of gallery item
  1. Insert a Label inside the gallery and set its Text property as:
ThisItem.ProdRowNumber
powerapps increment number in gallery

4. Save and preview the app. Try to enter any first letter of the product (either upper/lower case) inside the search box. You can see the gallery will filter according to the search product, including the individual row number as shown below.

Add Row Number to Gallery Dynamically in Power Apps

Add Power Apps Gallery Row Number Using a SharePoint List

Here, we will add the Power Apps gallery row number from a SharePoint list. I will use the same list above for this example.

Refer to the image below:

Add Power Apps Gallery Row Number Using a SharePoint List
  1. First, go to the App’s OnStart property and apply the formula below:
Clear(colProductRowNumber);
ForAll(
    'Sales Data',
    Collect(
        colProductRowNumber,
        Last(
            FirstN(
                AddColumns(
                    'Sales Data',
                    'RowIndex',
                    CountRows(colProductRowNumber) + 1
                ),
                CountRows(colProductRowNumber) + 1
            )
        )
    )
)

Where,

  • colProductRowNumber = Power Apps Collection Name
  • ‘Sales Data’ = SharePoint list
  • ‘RowIndex’ = Add a new column to specify the autogenerated number