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 gallery with SP c...
Power Apps
Answered

Sort gallery with SP choice field on button click

(0) ShareShare
ReportReport
Posted on by 249

I have a gallery connected to a SharePoint list. I want to be able to click on column headers (buttons) on the list so that the data in that column will be sorted. This is working fine for Text and Date fields but not Choice. Here is how I am achieving the Text/Date fields

Gallery Items: 

SortByColumns(
 *...gallery filtering...*
 sortCol,
 If(
 sortOrder,
 Ascending,
 Descending
 )
)

Sort by Title, on button click:

UpdateContext({sortCol:"Title",sortOrder:!sortOrder})

I tried adding.Value to the sortCol in the line above but that didn't work. Any suggestions?

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

    @cooper33 

    For this to work, you will need to get the value of the Choice column in your data.

    The way to do that is to AddColumns.

     

    SortByColumns(
     AddColumns(*...gallery filtering...*, 
    "txtChoice", yourChoiceColumn.Value), sortCol, If( sortOrder, Ascending, Descending ) )

    Then for sorting on that choice column:

    UpdateContext({sortCol:"txtChoice",sortOrder:!sortOrder})

    One thing to keep in mind...If you have any place that you are referring to the Gallery.Selected that is tied to the datasource (i.e. an EditForm that the Item resolves back to Gallery.Selected) then you will need to remove the added column in that property so that it does not conflict with the datasource signature.

     

    I hope that is helpful for you...

     

     

     

  • PytByt Profile Picture
    943 on at

    @RandyHayes wrote:

    @cooper33 

    For this to work, you will need to get the value of the Choice column in your data.

    The way to do that is to AddColumns.

     

    SortByColumns(
     AddColumns(*...gallery filtering...*, 
    "txtChoice", yourChoiceColumn.Value), sortCol, If( sortOrder, Ascending, Descending ) )

    Then for sorting on that choice column:

    UpdateContext({sortCol:"txtChoice",sortOrder:!sortOrder})

    One thing to keep in mind...If you have any place that you are referring to the Gallery.Selected that is tied to the datasource (i.e. an EditForm that the Item resolves back to Gallery.Selected) then you will need to remove the added column in that property so that it does not conflict with the datasource signature.

     

    I hope that is helpful for you...

     

     

     


    Hi @RandyHayes 

    Im a newbie powerapps developers, i need to know where is exactly i put those formula?


    And, what is this? 

    *...gallery filtering...*

     

    Thanks.

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

    @PytByt 

    In this particular case, @cooper33 was using a Gallery in the App and had an existing filter or other formula for the Items property of the Gallery.

    So, the proposed formula was to go into the Items property of the Gallery and the "*...Gallery Filtering...*" was meant to be whatever was currently in that Items property before changing the formula.

     

    I hope that is clear and helps you.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    thanks for this post. This gave me the answer I was desperately looking for. Just as a short amendment to Randy's solution, I'd like to propose to remove the additional column right after sorting, so that the problem Randy outlines at the bottom of his/her post won't occur:

    DropColumns(
    SortByColumns( AddColumns(*...gallery filtering...*,
    "txtChoice", yourChoiceColumn.Value), sortCol, If( sortOrder, Ascending, Descending ) ),
    "txtChoice"
    )

     

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