cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
GeorgeKirtland
Frequent Visitor

Sort By Date

Hi, As part of an app I am creating, I have a sharepoint list integrated via a Gallery, and am having trouble when sorting by Date.

 

I have created a search box, as well as the ability to click on any of the gallery "headers" to sort (ascending or descending as a toggle) via the header clicked.

 

The gallery code is as below:

 

SortByColumns(Search( 'List Name',SearchBox.Text,"Search Fields"), VarSortBy,If( VarSortOrder, Descending, Ascending))
 
List Name = Sharepoint List
Search Fields = a list of all columns on the sharepoint list
VarSortBy = Gets set to name of column when column header clicked on, to sort by that column
VarSortOrder = True or False to sort ascending or descending.
 
All sorts work fine apart from date, which sorts only based on the first number as opposed to taking the whole date into account. The date is formatted as "DD/MMM/YY" (i.e. 13/Nov/20).
 
As an example, it sorts like:
01/Apr/20
02/Nov/20
03/June/20
 
As opposed to:
01/Apr/20
03/June/20
02/Nov/20
 
How do I get it to take into account all of the date?
 
Thanks in advance.
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@GeorgeKirtland 

It looks like it is sorting this based on text and not date.  Is your Date column a real data column or is it text?

If it is text, then you can consider changing the formula to the following:

DropColumns(
    SortByColumns(
        AddColumns(
            Search('List Name', SearchBox.Text, "Search Fields"), 
            "realDate", DateValue(<actualDateColumnNameHere>)
        ),
        VarSortBy,
        If( VarSortOrder, Descending, Ascending)
    ),
    "realDate"
)

Keep in mind to sort on that added column "realDate" needs to be set from the action where you select the date column and set your VarSortBy - it should be set to "realDate" instead of whatever you are setting it to now.

 

Also, I included the DropColumns in this formula to avoid any issues you might have with utilizing the Gallery.Selected anywhere else in your app.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

2 REPLIES 2
RandyHayes
Super User III
Super User III

@GeorgeKirtland 

It looks like it is sorting this based on text and not date.  Is your Date column a real data column or is it text?

If it is text, then you can consider changing the formula to the following:

DropColumns(
    SortByColumns(
        AddColumns(
            Search('List Name', SearchBox.Text, "Search Fields"), 
            "realDate", DateValue(<actualDateColumnNameHere>)
        ),
        VarSortBy,
        If( VarSortOrder, Descending, Ascending)
    ),
    "realDate"
)

Keep in mind to sort on that added column "realDate" needs to be set from the action where you select the date column and set your VarSortBy - it should be set to "realDate" instead of whatever you are setting it to now.

 

Also, I included the DropColumns in this formula to avoid any issues you might have with utilizing the Gallery.Selected anywhere else in your app.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

That works absolutely perfectly, thank you so much @RandyHayes 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

PA Community Call

Power Apps Community Call

Next call is happening on April 21st at 8a PST.

MBAS Carousel

Sign up for our May 4th event!

May the fourth be with you, join us online!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Top Solution Authors
Top Kudoed Authors
Users online (48,134)