Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Sort Gallery by Month, Day, and Year NOT WORKING CORRECTLY!

(0) ShareShare
ReportReport
Posted on by 95

I have an app with a home page gallery that lists all the items, and it can be sorted and filtered by multiple categories. However, when the user goes in to click the sort arrow icon for the 'Go Live' date, the dates seem to be sorting by month, and not by the full month/day/year format. 

 

My ITEMS property of the Gallery is the following: 

 

Search(
 Sort(
 Filter(
 AddColumns(
 'BARC Submissions',
 "SubmissionOwnerName",
 SubmissionOwnerSearch.DisplayName
 ),
 IsBlank(ComboBox1.Selected.Value) || SubmissionStatusChoice.Value = ComboBox1.Selected.Value
 ),
 Switch(
 varSortColumn,
 "SubmissionName",
 'Submission Name',
 "SubmissionOwner",
 SubmissionOwnerSearch.DisplayName,
 "GoLive",
 DateTimeValue(GoLive),
 "SubmissionStatus",
 SubmissionStatusChoice.Value
 ),
 varSortOrder
 ),
 TextInput1.Text,
 "SubmissionName",
 "SubmissionOwnerName"
)

 

However, when the user clicks the sort icon next to Go Live, it sorts the dates by the month, day, and then year, so all the dates are mixed up... see my image here:


BARC_DateSortOrder.png
How do I fix this?? HELP PLEASE!

Categories:
  • russrimm Profile Picture
    Microsoft Employee on at
    Re: Sort Gallery by Month, Day, and Year NOT WORKING CORRECTLY!

    @cjwilson80 Did you get it resolved? If you ever get really stuck and your org has a Microsoft Unified support agreement, ping your CSAM - we have many cloud solution architects, like myself, focused on all things Power Platform who can help out with challenges like this!

  • Verified answer
    russrimm Profile Picture
    Microsoft Employee on at
    Re: Sort Gallery by Month, Day, and Year NOT WORKING CORRECTLY!

    Hi @cjwilson80 , so "Status" is populated from SubmissionStatus, correct?  If so, what column type is SubmissionStatus?  Choice?

     

    Try this out?

     

    With(
     {
     myData: Search(
     Sort(
     Filter(
     AddColumns(
     'BARC Submissions',
     "SubmissionOwnerName",
     SubmissionOwnerSearch.DisplayName
     ),
     IsBlank(ComboBox1.Selected.Value) || SubmissionStatusChoice.Value = ComboBox1.Selected.Value
     ),
     Switch(
     varSortColumn,
     "SubmissionName", 'Submission Name',
     "SubmissionOwner", SubmissionOwnerSearch.DisplayName,
     "SubmissionStatus", SubmissionStatusChoice.Value
     ),
     varSortOrder
     ),
     TextInput1.Text,
     "SubmissionName",
     "SubmissionOwnerName"
     )
     },
     With(
     {myData: 'BARC Submissions'},
     If(
     varSortColumn = "GoLive",
     Sort(
     myData,
     DateTimeValue(GoLive),
     If(
     varSortOrder = "Descending",
     SortOrder.Ascending,
     SortOrder.Descending
     )
     ),
     varSortColumn = "SubmissionName",
     Sort(
     myData,
     'Submission Name',
     If(
     varSortOrder = "Descending",
     SortOrder.Ascending,
     SortOrder.Descending
     )
     ),
     varSortColumn = "SubmissionOwner",
     Sort(
     myData,
     SubmissionOwnerSearch.DisplayName,
     If(
     varSortOrder = "Descending",
     SortOrder.Ascending,
     SortOrder.Descending
     )
     ),
     varSortColumn = "SubmissionStatus", // Add this condition
     Sort(
     myData,
     SubmissionStatus, // Assuming SubmissionStatus is the column name
     If(
     varSortOrder = "Descending",
     SortOrder.Ascending,
     SortOrder.Descending
     )
     )
     )
     )
    )

     

  • cjwilson80 Profile Picture
    95 on at
    Re: Sort Gallery by Month, Day, and Year NOT WORKING CORRECTLY!

    Hi @russrimm, THANK YOU THANK YOU THANK YOU! 

    This solution works for the "Go Live" column, but now I'm struggling to add back in the other sorts. When I click on the sort icon for a different column, the gallery goes blank. For instance, the "Status" column sort icon will make the gallery go blank if I click on it, because it's not in the new code. I know above you said I could add back in the switch, but I'm not sure how to go about this. Could you please provide a sample or solution for adding back the other columns?

    BARC_FilterSortInputs.pngBARC_Additional_ColumnsSort.png

     

    **I have the following code now in my "Items" property of the gallery. Everything seems to be working EXCEPT when I try to sort the "Status".... When I click the icon to sort "Status", the gallery goes blank. What am I missing?**

    With(
     {
     myData: Search(
     Sort(
     Filter(
     AddColumns(
     'BARC Submissions',
     "SubmissionOwnerName",
     SubmissionOwnerSearch.DisplayName
     ),
     IsBlank(ComboBox1.Selected.Value) || SubmissionStatusChoice.Value = ComboBox1.Selected.Value
     ),
     Switch(
     varSortColumn,
     "SubmissionName",
     'Submission Name',
     "SubmissionOwner",
     SubmissionOwnerSearch.DisplayName,
     "SubmissionStatus",
     SubmissionStatusChoice.Value
     ),
     varSortOrder
     ),
     TextInput1.Text,
     "SubmissionName",
     "SubmissionOwnerName"
     )
     },
     With(
     {myData: 'BARC Submissions'},
     If(
     varSortColumn = "GoLive",
     Sort(
     myData,
     DateTimeValue(GoLive),
     If(
     varSortOrder = "Descending",
     SortOrder.Ascending,
     SortOrder.Descending
     )
     ),
     varSortColumn = "SubmissionName",
     Sort(
     myData,
     'Submission Name',
     If(
     varSortOrder = "Descending",
     SortOrder.Ascending,
     SortOrder.Descending
     )
     ),
     If(
     varSortColumn = "SubmissionOwner",
     Sort(
     myData,
     SubmissionOwnerSearch.DisplayName,
     If(
     varSortOrder = "Descending",
     SortOrder.Ascending,
     SortOrder.Descending
     )
     )
     )
     )
     )
    )

    Sta 

  • russrimm Profile Picture
    Microsoft Employee on at
    Re: Sort Gallery by Month, Day, and Year NOT WORKING CORRECTLY!

    Hi @cjwilson80.  It is due to a limitation with the Sort() function and other functions that refer to columns by name. You must, without exception, provide column names as primitive strings. That is, hard-coded text values. You can't change the sort column using Switch to dynamically set the column as you are attempting to do here.

     

    To get around this limitation, you will have to write separate Sort() formulas, one for each column you wish to sort by, and then pick one using a Switch() or If() function.

     

    Here's a simplified example without the Filter, Search, and AddColumns (which can be added back into the 'With' function.)  I'm also assuming your varSortOrder is a boolean value that's being flipped between true/false by your sort icon.

     

     

     

    With(
     {myData: 'BARC Submissions'},
     If(
     varSortColumn = "GoLive",
     Sort(
     myData,
     DateTimeValue(GoLive),
     If(varSortOrder, SortOrder.Ascending, SortOrder.Descending)
     ),
     varSortColumn = "SubmissionName",
     Sort(
     myData,
     "Submission Name",
     If(varSortOrder, SortOrder.Ascending, SortOrder.Descending)
     )
     )
    )

     

     

     

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 1