Thomas VineThomas Vine Power Platform Developer

Creating a row number for gallery items

The Index function in Power Apps is super handy for returning a specified table record based on its ordered position. At the time of writing, there is no function to create a new column or read the index/row number inside an app.

Below is a Power Bite to create a new temporary column called RowNumber, which contains an index. Just replace “DataSource” with your own collection or data source and then place the code in the Gallery: Items property.

With(
    {
        Table: DataSource
    }, 
    ForAll(
        Sequence(
            CountRows(Table)
        ) As Seq,
        Patch(
            Last(
                FirstN(
                    Table,
                    Seq.Value
                )
            ),
            {
                RowNumber: Seq.Value
            }
        )
    )
)

Once you have updated the Gallery: Items property, you can reference the row number of the current item using ThisItem.RowNumber.

Quick tip: want the index to start at a different number from 1? Update the sequence function to Sequence(CountRows(Table), number).

Leave a Reply

Your email address will not be published. Required fields are marked *

Press ESC to close