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 By New Items to O...
Power Apps
Unanswered

Sort By New Items to Old Items in a Gallery

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi everyone, I'm new at PowerApps so I'm learning, I could use your help. I'm having issues making a sort by in a gallery that is created from a Sharepoint List. I want to display the Items from newest to oldest but I don't seem to get the right formula. I want to use the sort icon.

Any Ideas? 

 

Categories:
  • chrisog Profile Picture
    213 on at

    Hi @Anonymous,

     

    You can use the Sort or SortByColumns functions. I prefer the SortByColumns function but they are very similar

     

    The syntax is SortByColumns(myDataSource,"ColumnName", OrderToSortBy)

     

    If you wanted a sort button similar to sample screens, they work by using a Variable which, when you click on the sort button, inverts the value from true to false or vice versa.

     

    1. Create a sort button. You can use an icon, button, label -- anything you want. Set it's OnSelect property to:

    UpdateContext({SortDescending:!SortDescending})

    Note the ! reverses the boolean value, so you are creating a Variable with the name SortDescending and setting the value of that variable to the opposite of what it is currently. 

     

    2. Create your Gallery. The Gallery's Data Source should point to your data source, and the Items property should be something like:

    SortByColumns(myDataSource,"ColumnName", If(SortDescending,Descending,Ascending))

     

    The way this works is that the Variable SortDescending is either true or false, so the If statement determines whether to sort by Descending (If true) or Ascending (If false). If you want the Gallery to display by Descending (new - old) by default, have the OnVisible property of that screen declare the Variable as true with: 

    UpdateContext({SortDescending:true})

     

     

    I think this mostly covers your issue. Is there anything else that I can help with?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hey @chrisog ,

    I'm trying to use what you advised. Even though I think I'm no doing it in the right form. 

     

    image.png

     

    I have this gallery on the left, this is the one I would like to sort by date. 

     

    I filter this gallery by the drop-down above of it, the one that says 'My tasks'... 

     

    I would like to do both, to filter by the drop-down and also to sort the gallery by the date. 

     

    This is how I actually filter my gallery: 

    If(DropdownTasks.Selected.Value = "My Tasks", Filter('My Source','Created By'.Email = 'User Email Label'.Text),'My Source') 

     

    Should i integrate the sort formula to this items current formula? Or I can do it from the on select function of the sort icon?

     

    Please help!

  • chrisog Profile Picture
    213 on at

    Hi @Anonymous,

     

    You can definitely integrate your SortByColumns into your existing formula:

     

    If(DropdownTasks.Selected.Value = "My Tasks", SortByColumns(Filter('My Source','Created By'.Email = 'User Email Label'.Text),"myColumnName",If(SortDescending,Descending,Ascending)),SortByColumns('My Source',"myColumnName",If(SortDescending,Descending,Ascending))

     

     

     

  • v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

     

    chrisog's workaround looks perfect, please have a try and check if your issue is fixed.

    What is want to note is that you can use "ID" column to sort if you want to sort by items order, but if you want to sort by the modified date, you should use "Modified" column.

    Just replace "myColumnName" in chrisog's code by "ID" or "Modified" .

    Best regards,

    Sik

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

#2
Mohsin Ali Profile Picture

Mohsin Ali 347

#3
WarrenBelz Profile Picture

WarrenBelz 254 Most Valuable Professional

Last 30 days Overall leaderboard