Showing results for 
Search instead for 
Did you mean: 
Helper III
Helper III

Add a sort by date option to the browse screen

Hi there,


I have a simple data set showing on the browse screen of my app that already has the default sort ascending descending button, the OnSelect command is UpdateContext({SortDescending1: !SortDescending1}).  I have a text field on the screen that shows the date and time a record was added via the EditScreen and I would like to add a button to allow users to sort by date and time.


The text field that holds the date is named "Body1", so I tried putting "UpdateContext({SortAecending:Body1})" but I get a message saying there are side effects and it cannot be evaluated, does anyone have any advice for me?




Impactful Individual
Impactful Individual

Can you post a screenshot so we can see what exactly you’re referring to

Hopefully, the attached shows what I am trying to do...

Impactful Individual
Impactful Individual

Can you post your formula for the gallery items property
Also, you don’t want to refer to the control name but instead the field name in the table such as ‘date’.
I would do this:
Original button OnSelect:
If(Sort1 = false || IsBlank(Sort1),Set(Sort1,true),Set(Sort1,false))
New button OnSelect:
If(Sort2 = false || IsBlank(Sort2),Set(Sort2,true),Set(Sort2,false))

Then gallery items:
If(Sort1 = false || IsBlank(Sort1),
If(Sort2 = false || IsBlank(Sort2),
If(Sort2 = false || IsBlank(Sort2),
SortByColumns(datasource,”FirstColumn”,Descending), SortByColumns(DatasourceName,”FirstColumn”,Descending,”datecolumn”,Ascending)))

You may need to switch round the columns in the very last part depending on what you want it to sort by first/second
Prob need to change the quote marks also as writing this on my mobile

Ps. You can use updatecontext instead of set but I like to use all my variables on multiple screens, updatecontext doesn’t roam whereas set does

I’ve also not applied any initial filtering to the data source and you may have to put this formula in a variable and set it after each on select(gone blank and can’t think if items property can be set like this without the pc in front of me), if so do:
Set(GalleryItems,Formulaabove) in the onselects after the set/sort formula above and then in your gallery items just put: GalleryItems

Hi Delid4ve,


Many thanks for providing such detailed help.  I am new to this and working on it in between other tasks so responses are slow - apologies.  I will look at implementing your suggestions this evening, meantime I don't see gallery items in the property list to send you the code from.  I built the app from an Excel file if that has any bearing on that?


Thanks again,


Community Support
Community Support

Hi @AlanR ,


Is this app auto-generated by PowerApps after you selecting Home > Start from your data? If so, then actually you can see how does the gallery being sorted and filtered, by selecting the gallery control and check its Items property:


In this screenshot, my BrowseGallery1 is sorted by "Days" column in my excel table. And search records that contain a string typed in search box in "Days" or "Name" columns.


If I want to sort with multiple columns, then I should change this formula to:

SortByColumns(Search([@Table1], TextSearchBox1.Text, "Days","Name"), "Days", If(SortDescending1, Descending, Ascending),"Name", If(SortDescending1, Descending, Ascending))




Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-monli-msft Mona,


Many thanks for the help and so sorry for the delay responding.  I am new to apps so all of this is a bit complicated for me! I did build the app from the Excel data source as you thought, when I click on the BrowseGallery1 the attached is what I see.


Ideally I want to retain the search box functionality, have the records sorted by my Excel table field "Date of Incident" shown under the Body1 control on the screen shot, and keep the alphabetic sort option under the current sort up down button.  How do I get rid of the "x0020" style references? Is there a consequence if I do?


Appreciate your time educating me on this,




Hi @AlanR ,


What is the column name inside your table? If it is Description of Issue, then you just need to use "Description of Issue" ( enclosed in double quotes) in the formula directly.


In which order do you want to sort with "Date of Incident" column? I assume that you want to sort with Descending, then you just need to replace the "If(SortDescending1, Descending, Ascending)" for this column to "Descending". For example, my formula should be:

SortByColumns(Search([@Table1], TextSearchBox1.Text, "Days","Name"), "Days", Descending,"Name", If(SortDescending1, Descending, Ascending))




Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Mona, @v-monli-msft 


I have made some progress with your advice, thank you but I am still struggling with what I think should be a simple sort of records on the browse screen by date.  My screen shot in the attached tries again to explain what I am hoping to do, can you review and let me know what you recommend?


Many thanks,




@mdevaney  Hi mdevaney - this thread is the sorting by date problem I mentioned in my other post - monli was very helpful but I was not able to figure out the solution suggested, (likely just me being thick), can you help or clarify?



Helpful resources

October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

Ignite 2022


Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Solution Authors
Top Kudoed Authors
Users online (2,543)