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

Announcements

News and Announcements icon
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 259

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 395

#2
WarrenBelz Profile Picture

WarrenBelz 352 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 287 Super User 2026 Season 1

Last 30 days Overall leaderboard