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 / Sort / Filter Gallery ...
Power Apps
Answered

Sort / Filter Gallery items using buttons/icons

(0) ShareShare
ReportReport
Posted on by

I have a gallery with the following Items property

SortByColumns(Filter(Routing, (InitiatorText = _varUser.Email) && oStatus = 1), "Title", Ascending)

Outside of this gallery, I added column headers with up/down arrows.  How do I re-sort the gallery items? I tried:

Sort(GalleryName.AllItems, Title, SortOrder.Descending)

Data Source: SharePoint Online list 

Same with filter if user wants to filter the gallery using different values. I can do this by creating multiple galleries but wondering if it can be done with one gallery?

Categories:
  • Verified answer
    iAm_ManCat Profile Picture
    18,256 Most Valuable Professional on at

    Hi @Tamras 

     

    I would have your Up/Down Arrows Set a variable, then SortbyColumns on that.

    I am going to assume you mean you have only one up/down sort arrow, not one for each column, please let me know if that's not the case, as we can do that however it will take a bit more code.

     

    So your Up Arrow's OnSelect would be:

    Set(SortAscending, true)

     

    And your Down Arrow's OnSelect would be:

    Set(SortAscending, false)

     

    Then your formula becomes:

    SortByColumns(
    Filter(
    Routing,
    (InitiatorText = _varUser.Email) && oStatus = 1),
    "Title",
    If(SortAscending,
    Ascending,
    Descending,
    //This sets default sort Order
    Ascending
    )

    )

    This way, if your user selects one of the options, it will change the SortByColumn to Ascend/Descend depending on what you've chosen,

     

    Any trouble with this, let me know,

     

    Cheers,

    ManCat

  • Aethyta Profile Picture
    on at

    @iAm_ManCat  Thank you! It worked perfectly.

     

    I set my variables on a button that navigates to the screen where below gallery is located

    Set(_varSortBy, "Deadline"); Set(SortAscending, true);

    Since I have multiple columns, I ended up with the following formula for my Gallery Items property:

    SortByColumns(Filter(Routing, (InitiatorText = _varUser.Email) && oStatus = 1), _varSortBy, If(SortAscending, Ascending, Descending))

    Above formula received delegation warning in _varSortBy so I just used nested if to work around it as I really only need 3 columns with sort option.

    I added an icon on Title column with the following OnSelect property:

    UpdateContext({SortAscending: !SortAscending, _varSortBy: "Title"})

    Then changed the icon property to toggle between up/down:

    If(SortAscending, Icon.ChevronDown, Icon.ChevronUp)

     

  • jh4 Profile Picture
    24 on at

    I needed to sort a gallery by two columns; Document title and Document type (both ascending/descending). I also needed to filter those columns based on entries from previous selections. I began by creating a variable (sort1) and 2 buttons for each of the columns that would be sorted, one ascending and one descending. The buttons "on select" changed the value of the variable to 1,2,3 or 4 depending on the selected button. Set(sort1,1) etc...

    If(
     Sort1 = 1, Sort(Filter('Controlled Documents v3', Location = Dropdown2_11.Selected.Result , Process = Dropdown2_15.Selected.Result , 'Sub Process' = Dropdown2_13.Selected.Result),'Document Type',Ascending),
     Sort1 = 2, Sort(Filter('Controlled Documents v3', Location = Dropdown2_11.Selected.Result , Process = Dropdown2_15.Selected.Result , 'Sub Process' = Dropdown2_13.Selected.Result),'Document Type',Descending),
     Sort1 = 3, Sort(Filter('Controlled Documents v3', Location = Dropdown2_11.Selected.Result , Process = Dropdown2_15.Selected.Result , 'Sub Process' = Dropdown2_13.Selected.Result),'File name with extension',Ascending),
     Sort1 = 4, Sort(Filter('Controlled Documents v3', Location = Dropdown2_11.Selected.Result , Process = Dropdown2_15.Selected.Result , 'Sub Process' = Dropdown2_13.Selected.Result),'File name with extension',Descending)
    )

    I know it isn't the most elegant format. 😇  Thanks again for the support the previous posts helped me figure out where to start!

  • msh242 Profile Picture
    5 on at

    I need to apply this formula but I can't

     

    Filter('MONITOREO Y CONTROL',StartsWith(TRANSPORTE,"TransportesX") Or StartsWith(TRANSPORTE,"TransporteY"), and Switch(SortColumnPref,"Modified",SortByColumns('MONITOREO Y CONTROL',SortColumnPref,If(SortColumnModified,Ascending,Descending))))

  • mdevaney Profile Picture
    29,993 Moderator on at

    @msh242 
    I wrote a step-by-step tutorial on how to change the sort direction and column of a gallery using buttons or icons.  I'll leave a link to it below.

    Article: 'Power Apps Gallery Sort Controls'
    https://matthewdevaney.com/power-apps-gallery-sort-controls/

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • rroque Profile Picture
    350 on at

    Your solution doesn't work on canvas apps. Is there a solution for canvas app?

     
  • rroque Profile Picture
    350 on at

    Hi devaney, is there a solution to for cavvas apps?

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 350 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 318

#3
Mohsin Ali Profile Picture

Mohsin Ali 220

Last 30 days Overall leaderboard