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 / Gallery sort by date w...
Power Apps
Answered

Gallery sort by date with filtering

(0) ShareShare
ReportReport
Posted on by Microsoft Employee
Hi,

 

I am new to Power Apps and I have a gallery which is displaying data from an online excel spreadsheet, with the help of youtube I have managed to be able to filter the data with the use of dropdown's as well as searching by title column with a text input 

 

How can I make it so if I click the sort icon next to the date heading, it will sort the gallery by date (ascending and if clicked again descending)? 

 

powerapps-screenshot1.JPG

 

powerapps-screenshot2.JPG

 

 

 

Categories:
  • Verified answer
    WarrenBelz Profile Picture
    156,520 Most Valuable Professional on at

    Hi @Anonymous ,

    On the OnSelect of the Icon, put this

    UpdateContext({varSortD:!varSortD})

    Now you need to wrap your code in this (If you have supplied text, I could have corrected it for you). At the start, put

    Sort(

    then at the end

    ,
    Date,
    If(
     varSortD,
     Descending,
     Ascending
    ))

    I assume your field name is Date here.

     

    Please click Accept as solution 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 giving it Thumbs Up.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @WarrenBelz I did this but when pressing the sort icon, the gallery does not change

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @WarrenBelz I have this Text(ThisItem.Date,"[$-en-GB]d/m/yyyy") as the date item, could this be preventing the sort ?

  • WarrenBelz Profile Picture
    156,520 Most Valuable Professional on at

    @Anonymous ,

    Can you please provide the full code you have used in both places in Text. This has to work if all assumptions I made are correct.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @WarrenBelz 

    Sort(
    Search(
    If(
    catdrop.Selected.Result ="All" And locdrop.Selected.Result = "-", Table1,

    catdrop.Selected.Result = "All" And locdrop.Selected.Result <> "-",
    Filter(Table1, Location = locdrop.Selected.Result),

    catdrop.Selected.Result <> "All" And locdrop.Selected.Result = "-",
    Filter(Table1, Category = catdrop.Selected.Result),

    catdrop.Selected.Result <> "All" And locdrop.Selected.Result <> "-",
    Filter(Table1, Category = catdrop.Selected.Result And Location = locdrop.Selected.Result)),


    TextInput2.Text, "Title"),

    "Date",
    If(
    varSortD,
    Descending,
    Ascending
    ))

    Sort icon OnSelect = UpdateContext({varSortD:!varSortD})

     

  • WarrenBelz Profile Picture
    156,520 Most Valuable Professional on at

    @Anonymous ,

    Try this

    Search(
     Sort(
     Filter(
     Tablel,
     (catdrop.Selected.Result = "All" || Category = catdrop.Selected.Result) &&
     (Locdrop.Selected.Result = "-" || Location = Locdrop.Selected.Result)
     ),
     Date,
     If(
     varSortD,
     Descending,
     Ascending
     )
     ),
     Textlnput2.Text, 
     "Title"
    )

     

    Please click Accept as solution 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 giving it Thumbs Up.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @WarrenBelz - chucks a load of errors with sort, search and filter argument 

  • WarrenBelz Profile Picture
    156,520 Most Valuable Professional on at

    @Anonymous ,

    I could not test that, but this should work

    Sort(
     Filter(
     Tablel,
     (catdrop.Selected.Result = "All" || Category = catdrop.Selected.Result) &&
     (Locdrop.Selected.Result = "-" || Location = Locdrop.Selected.Result) && 
     (IsBlank(Textlnput2.Text) || Textlnput2.Text in Title)
     ),
     Date,
     If(
     varSortD,
     Descending,
     Ascending
     )
    )

    also note this is free-typed, so check for spelling/names etc - the syntax structure is valid if your values are.
    Also note the in Filter (and Search) are not Delegable, so you will get a warning and this will not work on tables over 2,000 items.

     

    Please click Accept as solution 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 giving it Thumbs Up.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I figured it, by taking your original suggestion, but changing Sort to SortByColumns - it then worked, accepted your answer as it lead me to the solution

  • WarrenBelz Profile Picture
    156,520 Most Valuable Professional on at

    @Anonymous ,

    That is because SortByColumns uses "Date" and Sort uses Date

    Have a look at my last post and you will see there is a far more efficient way of doing the Filter - also if you only have one field to search on, the in filter is a good option.

     

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 394 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 324 Most Valuable Professional

Last 30 days Overall leaderboard