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 / Dynamically changing o...
Power Apps
Answered

Dynamically changing order of items in gallery

(2) ShareShare
ReportReport
Posted on by 44

Hello all,

 

I've got a series of items in a gallery that contain an OrderPosition_Number column. The point of this column is to keep the records in a specific order. But the app needs to allow the user to manually change that order when needed.

 

Given the following table, how would you go about adding 2 icons to a gallery with an arrow up and an arrow down that would allow the user to move the order of it's own number and all the numbers around it? I'm completely stuck I have no idea where to start with this.

 

Example table:

I want the end user to move Tony to number 3, this means Peter and Ruper all have to be kicked down one number. 

NameOrderPosition_Number
Jasper1
Carl2
Peter3
Rupert4
Tony5
Categories:
I have the same question (0)
  • Verified answer
    Ramole Profile Picture
    Super User 2024 Season 1 on at

    Hi @Jargonaut 
    Please check this video by @developermct   Power Apps: Order or Reorder Items in a List or Gallery 
    after you watch, if you don't understand let me know and will help. also once you set up the sort order column it maybe not delegable the one showing on video but I will give you a delegable formula after don't worry.

     

    CaptureORDER.JPG

  • Jargonaut Profile Picture
    44 on at

    @Ramole it looked like it was working at first but it actually isn't working all the time.

     

    half the times when I click either up or down the order number goes down for a split second but returns to where it was.

     

    Any ideas?

     

    Patch(
     'impact_management.master_question_list',
     ThisItem,
     {
     temp_order_position: ThisItem.temp_order_position + 1.5
     }
    );
    // 
    // Put all the rows of data here and put it in a temporary collection
    //
    ClearCollect(
     colTempStatuses,
     Sort('impact_management.master_question_list'
    
     , 
     temp_order_position
     )
    );
    // 
    // Loop through all the values in our temp collection and assign whole numbers 
    // in sequence starting with 1, and so on. 
    //
    ForAll(
     Sequence(CountRows(colTempStatuses)),
     Patch(
     colTempStatuses,
     Index(Sort(colTempStatuses, SortOrder), Value),
     {
     temp_order_position: Value 
     }
     );
    );
    // 
    // Update the data in SharePoint
    //
    Patch(
     'impact_management.master_question_list',
     colTempStatuses
    );

     

    Regards

  • Ramole Profile Picture
    Super User 2024 Season 1 on at

    @Jargonaut 

    I am not near computer at moment but will have look you code later and amended then will share with 

     

  • Ramole Profile Picture
    Super User 2024 Season 1 on at

    @Jargonaut 

    Here is a working code but please modify according to you DataSource and column names, let me know how it went.


    ArrowUp

     

    Patch(
     RequestPriorities,
     ThisItem,
     {
     SortOrder: ThisItem.SortOrder - 1.5
     }
    );
    // 
    // Put all the rows of data here and put it in a temporary collection
    //
    ClearCollect(
     colTempPriorities,
     Sort(
     DropColumns( 
     RequestPriorities,
     "{VersionNumber}", 
     "Modified"
     )
     , 
     SortOrder
     )
    );
    // 
    // Loop through all the values in our temp collection and assign whole numbers 
    // in sequence starting with 1, and so on. 
    //
    ForAll(
     Sequence(CountRows(colTempPriorities)),
     Patch(
     colTempPriorities,
     Index(Sort(colTempPriorities, SortOrder), Value),
     {
     SortOrder: Value 
     }
     );
    );
    // 
    // Update the data in SharePoint
    //
    Patch(
     RequestPriorities,
     colTempPriorities
    )
    //END OF CODE =============================================

     


    ArrowDown

     

    //CODE =============================================
    // 
    // This patch will move any item one slot higher by subtracting the value of 1.5
    //
    Set(
     gblShowSpinner,
     true
    );
    Patch(
     RequestPriorities,
     ThisItem,
     {
     SortOrder: ThisItem.SortOrder + 1.5
     }
    );
    // 
    // Put all the rows of data here and put it in a temporary collection
    //
    ClearCollect(
     colTempPriorities,
     Sort(
     DropColumns( 
     RequestPriorities,
     "{VersionNumber}", 
     "Modified"
     )
     , 
     SortOrder
     )
    );
    // 
    // Loop through all the values in our temp collection and assign whole numbers 
    // in sequence starting with 1, and so on. 
    //
    ForAll(
     Sequence(CountRows(colTempPriorities)),
     Patch(
     colTempPriorities,
     Index(Sort(colTempPriorities, SortOrder), Value),
     {
     SortOrder: Value 
     }
     );
    );
    // 
    // Update the data in SharePoint
    //
    Patch(
     RequestPriorities,
     colTempPriorities
    );
    //END OF CODE =============================================

     

     

  • Ramole Profile Picture
    Super User 2024 Season 1 on at

    @Jargonaut 
    Did you get the idea?

  • rcallan Profile Picture
    25 on at

    Hi Jargonuat,

     

    I assume at this stage you have a working solution but for anyone else looking for a solution I have devised a neater solution

     

    As we are either moving one position up or one position down, I'm using variables to store the current and new position, then patch the 2 items to be switched with the other items position. Here is the full solution

     

    Gallery Items

    Sort(
     [YourSource],
     [YourOrderColumn]
    )

     

    Up Arrow - OnSelect

    UpdateContext(
     {
     varCurrentOrderPos: ThisItem.[YourOrderColumn],
     varNewOrderPos: ThisItem.[YourOrderColumn]-1 //current position - 1
     
     }
    );
    //Increase Order of Previous item by 1
    Patch(
     [YourSource],
     LookUp(
     [YourSource],
     [YourOrderColumn] = locNumberNewOrderPos
     ),
     {
     [YourOrderColumn]: locNumberCurrentOrderPos,
     }
    );
    //Decrease Order of Current Item by 1
    Patch(
     [YourSource],
     ThisItem,
     {
     [YourOrderColumn]: locNumberNewOrderPos
     }
    );

     Up Arrow - Visible

    ThisItem.[YourOrderColumn] > 1 //hide if item is first

     

    Down Arrow - On Select

    UpdateContext(
     {
     varCurrentOrderPos: ThisItem.[YourOrderColumn],
     varNewOrderPos: ThisItem.[YourOrderColumn]+1 //current position + 1
     
     }
    );
    //Decrease Order of Next Item by 1
    Patch(
     [YourSource],
     LookUp(
     [YourSource],
     [YourOrderColumn] = locNumberNewOrderPos
     ),
     {
     [YourOrderColumn]: locNumberCurrentOrderPos,
     }
    );
    //Increase Order of Current Item by 1
    Patch(
     [YourSource],
     ThisItem,
     {
     [YourOrderColumn]: locNumberNewOrderPos
     }
    );

     Down Arrow - Visible

    ThisItem.[YourOrderColumn] < [YourSource].AllItemsCount //Use variable to store total rows to avoid delegation warning

     

  • fvfd67100 Profile Picture
    2 on at

    Hello, Can you tell me how and where did you set this ?

    locNumberNewOrderPos

    I am trying to do this with Dataverse and at the moment it's not working

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!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 103

#2
WarrenBelz Profile Picture

WarrenBelz 82 Most Valuable Professional

#3
wolenberg_ Profile Picture

wolenberg_ 67 Super User 2026 Season 1

Last 30 days Overall leaderboard