Showing results for 
Search instead for 
Did you mean: 
Advocate I
Advocate I

Iterate through a Galleries list

I have a gallery that shows a history of activites for a contact.  When you click on a history activity it brings you to the details screen.  Right now the details screen Form is bound to the Galleries.selected property.  I'm trying to be able to give the user controls on the detail form to go to the next / previous record in the Gallery, without going back to the Gallery.  Is there an index exposed that you can access these items like in a Collection or Dictionary?

Power Apps
Power Apps


PowerApps does not support random access into any tabular data sources (something akin to "array accesses"). The closest pattern that one could use to reference a specific row in a collection, is a lookup with respect to a specific field that uniquely identifies that row. The field could be numeric, and it could in fact even be 0-based like the type of index you are hinting at:


    CustomerId  Name

    0             Bob

    1             Alice

    2             Mary


= LookUp(Customers, CustomerID = desired_index_here)


Your extension that allows navigation back and forth would have to maintain this state (for example a CustomerID, in a context variable), and to either (1) drive gallery selection using it, in a way similar to the above; which will in turn drive the form, or (2) bind the form directly to something like the above:


    Form1.DataSource = Customers

    Form1.Item = LookUp(Customers, CustomerID = currentCustomerID)

    NavBackButton.OnSelect = UpdateContext({ currentCustomerID: currentCustomerID - 1 })

    NavForwardButton.OnSelect = UpdateContext({ currentCustomerID: currentCustomerID + 1 })


I hope this helps.

Radu Gruian [MSFT] ** PowerApps Staff

It does but my data source does not have a field like that.  This list is would be around 50 items out of 300000+.  Unless you can copy the filtered data to a temp table or collection and add an autonumber column to index it I don't think this can work yet.



What back end are you using to store your data? Can you add a computed column on the server side that gives you the "index" ?

Radu Gruian [MSFT] ** PowerApps Staff

My backend is a SQL server but its the main table in my on-prem CRM app.  I could add this as an index but I'd rather not since the CRM application itself is a little shaky to begin with.

Community Champion
Community Champion

Hi rgruin:


I have learnt your iteration. Thanks.


However, I wish to share my thought on that.

If you BACK and NEXT beyong the CustomerID, the action will never resume.

I will tried on following condition based on CDM RecordId.

Say: 112233, 112234, 112235, 112236,..., 112250

On BACK, it may go to 112232, no record found. Even press NEXT again, it will increment NOT goto 112233.

On NEXT, it may go to 112251, no record found, and even pressing BACK again, it will NOT goto 112250.


Hence, I would suggest to include a validation of if it has hit Max(RecordId) and and stop UpdateContext.


Hope I am wrong, NOT right!



Of course. Please do include as much validation as needed to ensure that your back/forward navigation stays within the appropriate bounds. My formulas were for reference only, so I needed them to be as simple as possible so they could be easily understood. I don't know what your specific scenario is, but feel free to make use of e.g. LookUp to detect whether the previous/next record actually exists -- before decrementing/incrementing the ID, respectively.


For example:


    BackButton.OnSelect = If(!IsBlank(LookUp(Customers, CustomerID = customerId - 1)), UpdateContext({ customerId: customerId - 1}))

    FwdButton.OnSelect = If(!IsBlank(LookUp(Customers, CustomerID = customerId + 1)), UpdateContext({ customerId: customerId + 1}))


Additionally, you may want to disable the Prev/Next buttons when you reach the bounds, so you can't even go past either of them:


    BackButton.Disabled = IsBlank(LookUp(Customers, CustomerID = customerId - 1))

    FwdButton.Disabled = IsBlank(LookUp(Customers, CustomerID = customerId + 1))


Also, make sure that your customerId variable is properly initialized to begin with.


Radu Gruian [MSFT] ** PowerApps Staff
Community Champion
Community Champion

Hi rguin:


Yes, appreciate very much of the validation which are what I mean.

Thanks for sharing and I am very sure that will help many.


Have a nice day.


Is there any way to index from powerapps studio through a column that contains the values (1,2,3,4,5, etc)?.

The fact is that I already have a table indexed from CDM.
But when filtering it, the RecordId values remain discontinuous. For example:

{{RecordId: 112230}, {RecordId: 112231}, {RecordId: 112235}, {RecordId: 112236}, {RecordId: 112240}, etc.}...

We need the AddColumnIndex formula!!... Thank you and I await your response...

Helpful resources

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Top Solution Authors
Users online (4,752)