web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Dates not sorting corr...
Power Apps
Unanswered

Dates not sorting correctly

(0) ShareShare
ReportReport
Posted on by 64

The dates in my data table are not sorting correctly. I want the newest dates on top. When I select 10/24 for instance, data from 9/27 appears above data from 10/18.

 

This is the formula I'm using. 

SortByColumns
(
 Filter
 (
 'Data'
 ,DateTimeValue(ProductionTime) < DatePicker1.SelectedDate
 && DateTimeValue(ProductionTime) > DateAdd(DateTimeValue(DatePicker1.SelectedDate),-2,Months)
 )
 ,"ProductionTime"
 ,Descending
)

 

Categories:
I have the same question (0)
  • AaronKnox Profile Picture
    514 Super User 2024 Season 1 on at

    The SortByColumns is sorting properly:  "ProductionTime" is still considered text/single line of text because you are using the DateTimeFunction inside the Filter() function which still returns just a single line of text.  The DateTimeFunction is only getting the correct records and not actually transforming ProductionTime into a date that can be sorted.

     

    Use AddColumns to transform the text column type ProductionTime into a date column type, for example:

    AddColumns('Data',"_ProductionTimeDATE",DateTimeValue(ProductionTime))

    This gives you an extra column that is a date:

    CaptureD3.PNG

     

    The solution is to replace 'Data' from your original code with the AddColumns formula above:

    SortByColumns (
     Filter (
     AddColumns('Data',"_ProductionTimeDATE",DateTimeValue(ProductionTime))
     ,DateTimeValue(ProductionTime) < DatePicker1.SelectedDate 
     && DateTimeValue(ProductionTime) > DateAdd(
     DatePicker1.SelectedDate,
     -2,
     Months
     )
     )
     ,"_ProductionTimeDATE"
     ,Descending
    )

    Now the data table sorts properly (using the list testChoices instead of 'Data'):

    CaptureD4.PNG

     

     

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard