Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Gallery sorting not working

(0) ShareShare
ReportReport
Posted on by 22,034 Super User 2025 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!

  • BCBuizer Profile Picture
    22,034 Super User 2025 Season 1 on at
    Re: Gallery sorting not working

    Thanks Randy!

     

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

  • Verified answer
    RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on at
    Re: Gallery sorting not working

    @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,034 Super User 2025 Season 1 on at
    Re: Gallery sorting not working

    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.

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on at
    Re: Gallery sorting not working

    @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.

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,695 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,015 Most Valuable Professional

Leaderboard