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 / Ssorting for a collection
Power Apps
Unanswered

Ssorting for a collection

(0) ShareShare
ReportReport
Posted on by 260

Can't get this to work properly; maybe you can help.

 

I have a collection that I want to sort on two different fields independetly: name and date.  I created a header pver the top of the gallery and inserted a button for each field with a "symbol" in the button of either an up or down arrow to indicate when the order was ascending or descending.  Maybe dis regard that for this question other than to say the symbol reverses properly when the button is selected.

 

What doesn't work is the display of gallery records.  Whatever order was displayed remains the same.

I tried the following action for the button select:

 

SortByColumns(colSOHdr, "Date", If(varDatetSort, SortOrder.Ascending, SortOrder.Descending))

and set items for the gallery to colSOHdr.

 

I also tried items set to the SortByColumns and then just Sort using the same expression.

Next, for the button on select, I tried starting with a ClearCollect and re-doing the collects uned to create the collection; the onstart expression does a lot of filtering and works as expected, but when this is replicated by the button, the gallery display does not change no matter what the value  of items is.

 

I full y believed that a ClearCollect(colSOHdr, SortbyColimns("Date", <order>)) would then show the gallery in the new order but alas no.  Certainly error on my part, but what?

Categories:
  • timl Profile Picture
    37,287 Super User 2026 Season 2 on at

    Hi @lmheimendinger 

    Your post doesn't show the formula for your sort button.

    Let's say that the OnSelect formula for your button is this:

    UpdateContext({varDatetSort: !varDatetSort})

     

    If you then set the Items property of your gallery to the formula below, the button should sort the records as expected.

    SortByColumns(colSOHdr, "Date", If(varDatetSort, SortOrder.Ascending, SortOrder.Descending))

     

  • lmheimendinger Profile Picture
    260 on at

    I am not using UpdateContext but rather the following

     

    If(varDateSort = "v",
    Set(varDateSort, Char(94)),
    Set(varDateSort, "v")
    );

    ClearCollect(colSOHdr, Filter('Sales Orders Created Online',
    Date >= dteFromDate.SelectedDate,
    Date <= dteToDate.SelectedDate
    );

    SortByColumns(colSOHdr, "Date", If(varDateSort, SortOrder.Ascending, SortOrder.Descending));

     

    varDateSort is up or down arrow head for ascending or descending order.  And yes I  could just add ortByColumns to the ClearCollect exression but was trying to keep it granular until it works.

     

    Here is an additional wrinkle to the items expression in the gallery:  I also want it to sort by name in either descending or ascending order so it becomes

     

    SortByColumns(colSOHdr, "Name", If(varNameSort, SortOrder.Ascending, SortOrder.Descending), "Date", If(varDateSort, SortOrder.Ascending, SortOrder.Descending));

     

    Name sort is another button but operates just like Date sort.  Each does its own clearcollect.

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 405 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 368

#3
WarrenBelz Profile Picture

WarrenBelz 244 Most Valuable Professional

Last 30 days Overall leaderboard