cancel
Showing results for 
Search instead for 
Did you mean: 

New Function : Index - to index a table with a sequential number

It would be GREAT to have a function such as Index that would index a table and return a Table with an added column containing a sequential number based on the order of the Rows in the table.

 

Example:  Index(tableName, "indexColumn")   would return a table of the tableName table with an added column containing the sequential number of the row in the order of the table.

 

Why this Idea?  Because there are a lot of Ideas on the forum that revolve around this in some way - "collection with an index", "index for a gallery row", etc.   While it would be nice to have those individually, a quicker way to get there would be to provide an Index function that could be used for all of them.

 

The Function would be equivalent to the following (based on the mentioned syntax above):

 

ForAll(
    Sequence(CountRows(tableName)),
        Patch(Last(FirstN(tableName, Value)), {indexColumn: Value})
    )
)

 

Which is perfect at indexing a table...

But this would be MUCH more convenient as a Function in PowerApps.

 

I would not expect this to be delegable...just convenient!

Status: New
Comments
Steve_CRP
Regular Visitor

Small correction to the function in case someone tries to use it in their app:

 

ForAll(
    Sequence(CountRows(tableName)),
    Patch(tableName, Last(FirstN(tableName, Value)), {indexColumn: Value})
)

 

I much prefer this formula to the one where you have to copy everything into a new collection.
One thing I found was I needed to have indexColumn already defined in my collection first (although initially it was all zeroes).

Would be great just to have an Index function though.

mdevaney
Super User

@RandyHayes 
The Power Apps INDEX function is now available!  The syntax is Index(Table, Index) where table is a table of values and Index is the row number.

Check out this documentation I wrote for it:
https://www.matthewdevaney.com/how-to-use-the-power-apps-index-function/

mdevaney_0-1650026272615.png

 

8BitWarrior
Advocate III

@mdevaney 

That can be a useful function no doubt, but I think the goal here is to apply an index to a data source (collection or list), which would open up the following functionality:

1. filter your data source using an index range  ( filter record between indexes 237-299)
2. apply pagination to a gallery (cycle through your data source 10, 25, 50 or more record at a time)