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 Apps
Suggested Answer

Up and Down arrows

(0) ShareShare
ReportReport
Posted on by 2
 
I am trying to create a system where the entries include, a location, a contact number, and the person to contact. I want to be able to use the up and down arrows to sort the list by location. 
 
I am using the following command, but it does not seem to work. I have eliminated the patch command since it does not seem to be reelevate to what I am trying to achieve. Any direction with this would be great!
 
 
// Move Item Up
UpdateContext({varCurrentItem: ThisItem});
UpdateContext({varTargetItem: Last(FirstN(Sort('To Do Lists', 'Location', SortOrder.Ascending), CountRows(FirstN(Sort('To Do Lists', 'Location', SortOrder.Ascending), ThisItem.'Location' - 1)) - 1))});
 
 
 
Categories:
I have the same question (0)
  • Suggested answer
    11manish Profile Picture
    3,333 on at
    Use a variable to control sort direction
     
    On your ↑ button:
    • UpdateContext({varSortOrder: SortOrder.Ascending})
    On your ↓ button:
    • UpdateContext({varSortOrder: SortOrder.Descending})
    Gallery Items property:

    Sort(
        'To Do Lists',
        Location,
        varSortOrder
    )
     
  • Suggested answer
    WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    I am assuming here that you want to dynamically re-order the entries in the gallery, swapping each with either the one below or the one above. The first thing you need here is a unique numerical identifier and one way of doing this would be to make a collection. The original Items of the gallery can be inserted where indicated below. Note that this would include static filters - any dynamic filters based on app controls would need to be done on the collection.
    With(
       {_List: YourCurrentGalleryItemsHere},
       ClearCollect(
          colToDo,
          ForAll(
             Sequence(CountRows(_List)),
             Patch(
                Index(
                   _List,
                   Value
                ),
                {RowNo: Value}
             )
          )
       )
    )
    and the Items of the Gallery is now
    Sort(
       colToDo,
       RowNo
    )
    Now your Up Arrow OnSelect
    With(
       {
          _Present: ThisItem.RowNo,
          _New: ThisItem.RowNo - 1
       },
       Patch(
          colToDo,
          LookUp(
             colToDo,
             RowNo = _New
          ),
          {RowNo: 0}
       );
       Patch(
          colToDo,
          LookUp(
             colToDo,
             RowNo = _Present
          ),
          {RowNo: _New}
       );
       Patch(
          colToDo,
          LookUp(
             colToDo,
             RowNo = 0
          ),
          {RowNo: _Present}
       )
    )
    and your Down Arrow OnSelect
    With(
       {
          _Present: ThisItem.RowNo,
          _New: ThisItem.RowNo + 1
       },
       Patch(
          colToDo,
          LookUp(
             colToDo,
             RowNo = _New
          ),
          {RowNo: 0}
       );
       Patch(
          colToDo,
          LookUp(
             colToDo,
             RowNo = _Present
          ),
          {RowNo: _New}
       );
       Patch(
          colToDo,
          LookUp(
             colToDo,
             RowNo = 0
          ),
          {RowNo: _Present}
       )
    )
    What you are effectively doing is  
    1. Temporarily flagging the above or below item to be renumbered by setting the RowNo to zero
    2. Setting the item chosen to replace it to its original position number
    3. Setting the temporary item to the original chosen item position
    The gallery sort will then take care of the new positions.
     
    Lastly the Visible of your Up Arrow - ensures you cannot move the first one up or the last one down.
    ThisItem.RowNo <> First(colToDo).RowNo
    and your Down Arrow Visible
    ThisItem.RowNo <> Last(colToDo).RowNo
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog
    Practical Power Apps    LinkedIn  
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    A quick follow-up to see if you received the answer you were looking for. Happy to assist further if not.
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like â™¥
    Visit my blog
    Practical Power Apps    LinkedIn   
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    Can you please let me know if this worked - I built  model for your query and it functions as expected here.
  • RobElliott Profile Picture
    10,521 Super User 2026 Season 1 on at
    Just to chip in my 2 euros worth, I did it slightly differently for my Desert Island Discs app by using the Sequence function:

     
    The gallery items property is: 
     
    SortByColumns(Filter([@'Desert Island Discs'], Sequence <=10), "Sequence")
     
    The OnSelect of the green chevron up button is:
     
    Select(Parent);
    //
    // This patch will move the item one place up by subtracting 1.5
    //
    Patch(
        'Desert Island Discs',
        ThisItem,
        {
            Sequence: ThisItem.Sequence - 1.5
        }
    );
    Select(btnReIndex)
     
     
    And the red down chevron OnSelect is:
     
    Select(Parent);
    //
    // This patch will move the item down 1 place by adding 1.5
    //
    Patch(
        'Desert Island Discs',
        ThisItem,
        {
            Sequence: ThisItem.Sequence + 1.5
        }
    );
    Select(btnReIndex)
     
    A hidden button brnReIndex is selected at the end of each OnSelect and has the following:
     
    ClearCollect(
        colTempSequence,
        Sort(
            'Desert Island Discs',
            Sequence, 
            SortOrder.Ascending
        )
    );
    // 
    // Loop through all the values in the temp collection and assign whole numbers 
    // in sequence starting with 1 
    //
    ForAll(
        Sequence(CountRows(colTempSequence)),
        Patch(
            colTempSequence,
            Index(Sort(colTempSequence, Sequence), Value),
            {
                Sequence: Value 
            }
        );
    );
    
    Patch(
        'Desert Island Discs',
        colTempSequence
    );
     
     
    Rob
    Los Gallardos
    Principal Consultant, Power Platform, WSP Global (and classic 1967 Morris Traveller driver)
  • KB-05050038-0 Profile Picture
    2 on at
    Can you explain how to incorporate Sequence, I have tried something like this but it does not seem to work.

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 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard