web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Next and Previous Item...
Power Apps
Answered

Next and Previous Item in Gallery

(0) ShareShare
ReportReport
Posted on by 257

Hey Guys,

 

I have a simple gallery with some numbers (red rectangle) I want to go through them with 2 buttons ( + -) and display that value on a label

JoaoSantos489_0-1667818213008.png

 

It should work like this.

*Press +*

2->3

*Press -*

3->2

 

Thanks in advance

Categories:
I have the same question (0)
  • Verified answer
    Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on at

    So...

     

    What do you have on your form "Item property"?

     

    If you have an item from a Gallery, try this:

     

    2->3
    LookUp( DataSource, Id = (LookUp(DataSource, Id = Gallery.Selected.Id).Id + 1))

     

    3->2
    LookUp( DataSource, Id = (LookUp(DataSource, Id = Gallery.Selected.Id).Id - 1))

     

    If you need additional help please tag me in your reply and please like my reply.
    If my reply provided you with a solution, pleased mark it as a solution ✔️!

    Best regards,

    Gonçalo Nogueira

    Check my LinkedIn!

    My website!

    My blog!

  • Akser Profile Picture
    1,546 Moderator on at

    Hi @JoaoSantos489,

     

    Add this formula to OnSelect of both + and - buttons. This will (only once) create a temporary collection with a new column that will allow us to go to the next / previous row.

     

    // Create new collection with only the key column from the gallery
    If(
     IsEmpty(colMyGallery),
     ClearCollect(
     colMyGallery,
     ShowColumns(
     galMyGallery.AllItems,
     "ID"
     )
     )
    );
    // Create new collection based on first collection with one extra column that contains an auto increment number "MyID"
    If(
     IsEmpty(colMyNumberedGallery),
     ForAll(
     colMyGallery,
     Collect(
     colMyNumberedGallery,
     Last(
     FirstN(
     AddColumns(
     colMyGallery,
     "MyID",
     CountRows(colMyNumberedGallery) + 1
     ),
     CountRows(colMyNumberedGallery) + 1
     )
     )
     )
     )
    );

     

     Now add this to + button

     

    // Retrieve next item from gallery and store its ID in a variable
    Set(
     varSelectedItem,
     LookUp(
     colMyNumberedGallery,
     LookUp(
     colMyNumberedGallery,
     ID = ThisItem.ID,
     MyID + 1
     ) = MyID,
     ID
     )
    );

     

    And this to - button

     

    // Retrieve previous item from gallery and store its ID in a variable
    Set(
     varSelectedItem,
     LookUp(
     colMyNumberedGallery,
     LookUp(
     colMyNumberedGallery,
     ID = ThisItem.ID,
     MyID - 1
     ) = MyID,
     ID
     )
    );

     

    Now varSelectedItem will have an ID value. You can use that to display the information you want. 

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard