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 / Gallery sorting not wo...
Power Apps
Answered

Gallery sorting not working

(0) ShareShare
ReportReport
Posted on by 22,722 Super User 2026 Season 1

Hi All,

 

I'm creating a gallery in which items can be sorted by the user using two arrow icons to move them up or down:

BCBuizer_0-1634673097135.png

Pressing the icons updates a column called 'Sorting order', for instance:

 

OnSelect= Set(varSort,ThisItem.SortOrder);
Patch(collection,LookUp(collection,SortOrder=Text(Value(varSort+1))),{SortOrder:varSort});
Patch(collection,LookUp(collection,ID=ThisItem.ID),{SortOrder:Value(varSort)+1})

 

In turn, the gallery is sorted, based on the value of the Sort Order column:

 

Items = 
Sort(
 Filter(
 collection,
 IsBlank(LinkedDocument)
 ),
 "SortOrder",
 Descending
)

 

As you can see in the above picture, initially this gives the correct order (the number is ThisItem.'Sort Order'). When clicking on either of the item, the values of the Sort Order change correctly, yet the order of the items in the gallery doesn't (clicked 'Up' on the bottom, red item):

BCBuizer_1-1634673595963.png

Can anybody give an idea of what should do to get the order of the item in the gallery to what it should be? Thanks!

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @BCBuizer 

     

    The trick is changing the proper records in your table and realizing that once you change one, then logic for the next on is missing.

     

    Easier to demonstrate than to explain.

     

    Please see the attached app.  Download it and save it.  Then in PowerApps, edit an existing app or create a new app, then then go to File -> Open   Then Browse for the file you downloaded.

     

    It is a full operational re-ordering gallery.  The only formulas in it are on the OnSelect of the up and down arrows.  The data used is created in the OnCheck action of Toggle1 in it.  Nothing else going on.

     

    Take a look and see if it is helpful for you.

     

  • BCBuizer Profile Picture
    22,722 Super User 2026 Season 1 on at

    Hello Randy,

     

    Thanks for the reply. I see your point, but I though I had addressed that.

     

    When running your app the sorting works, but when I adapted the code for the arrows to my app, the result was the same.

     

    OnSelect= 
    With({_current: LookUp(collection, Value('Sort Order')=ThisItem.'Sort Order' +1)},
    
     UpdateIf(collection, 'Sort Order'=ThisItem.'Sort Order', {'Sort Order': ThisItem.'Sort Order'+1});
     Update(collection, _current, Patch(_current, {'Sort Order': ThisItem.'Sort Order'}));
    )

     

    BCBuizer_0-1634677039734.png

     

    Could the issue be in the fact that 'Sort Order' is a text type column?

    *Edit: I just changed the column type to number and it doesn't make a difference.

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @BCBuizer 

    Your sort order should be numeric.

    Your formula for the down arrow:

    With({_current: LookUp(collection, 'Sort Order'=ThisItem.'Sort Order' +1)},
    
     UpdateIf(collection, 'Sort Order'=ThisItem.'Sort Order', {'Sort Order': ThisItem.'Sort Order'+1});
     Update(collection, _current, Patch(_current, {'Sort Order': ThisItem.'Sort Order'}));
    )

    ...is correct - except you should not be using the Value function on Sort Order. 

    This above should be giving you what you need.

     

    If not, try to invoke the down button and then take a look at your collection to see what values it has for the two rows in question.

     

    Also, just to be sure, your Items property on the Gallery should be:

    Sort(
     Filter(
     collection,
     IsBlank(LinkedDocument)
     ),
     'Sort Order'
    )

    NOTE: This is an alteration of your original Items property as it was not correct.

  • BCBuizer Profile Picture
    22,722 Super User 2026 Season 1 on at

    Thanks Randy!

     

    Turns out I was sorting by "SortOrder" instead of 'Sort Order'.... Thanks for pointing that out!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 839

#2
Valantis Profile Picture

Valantis 533

#3
Haque Profile Picture

Haque 412

Last 30 days Overall leaderboard