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

Sort does not work correct when filter contains date

my sort changes once i add a date in the filter. if i remove the date from the filter the sort shows the latest by date created when i add the date to the filter is sort change to QC_LOT_NUMBER ascending and Date Created Descending. ive removed everything except the date but same issue.

 

does anyone know how i can resolve this issue?

 

SortByColumns(
Filter(ZZQCLTS

,StartsWith(QC_LOT_NUMBER,LotSearch.Text)
,StartsWith(PART_NUMBER,PartNumSearch.Text)
,StartsWith(COMMERCIAL_PART_NO , CommerialPartSearch.Text)
,If(!IsBlank(DatePicker1.SelectedDate), DateValue( DATE_MANUFACTURED,"EN-us") = DatePicker1.SelectedDate , true)
), "DATE_CREATED", Descending)

9 REPLIES 9
WarrenBelz
Super User
Super User

Hi @agonciulea ,

The code below (slightly modified) should certainly sort by DATE_CREATED descending - are you saying it does not?

SortByColumns(
   Filter(
      ZZQCLTS,
         StartsWith(QC_LOT_NUMBER,LotSearch.Text),
         StartsWith(PART_NUMBER,PartNumSearch.Text),
         StartsWith(COMMERCIAL_PART_NO,CommerialPartSearch.Text),
         (IsBlank(DatePicker1.SelectedDate) || DateValue(DATE_MANUFACTURED,"EN-us") = DatePicker1.SelectedDate)
      )
   ),
   "DATE_CREATED", 
   Descending
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

Unfortunately that didnt work

 

here are the result with out the date filter 

agonciulea_1-1646349762706.png

 

 

here are the results with the date filter

agonciulea_0-1646349750552.png

 

here is the formula, i did change the !IsBlank to IsBlank but 

 

Sort(
Filter(
ZZQCLTS,
StartsWith(QC_LOT_NUMBER,LotSearch.Text),
StartsWith(PART_NUMBER,PartNumSearch.Text),
StartsWith(COMMERCIAL_PART_NO, CommerialPartSearch.Text),
(IsBlank(DatePicker1.SelectedDate) || DateValue(DATE_MANUFACTURED, "EN-us") = DatePicker1.SelectedDate)
),
DATE_CREATED,
Descending
)

Hi @agonciulea ,

Your code

Sort(
   Filter(
      ZZQCLTS,
      StartsWith(QC_LOT_NUMBER,LotSearch.Text),
      StartsWith(PART_NUMBER,PartNumSearch.Text),
      StartsWith(COMMERCIAL_PART_NO, CommerialPartSearch.Text),
      (IsBlank(DatePicker1.SelectedDate) || DateValue(DATE_MANUFACTURED, "EN-us") = DatePicker1.SelectedDate)
   ),
   DATE_CREATED,
   Descending
)

has to sort on DATE_CREATED, descending if your filter returns data and DATE_CREATED is a Date/Time field in your List ZZQCLTS. Your images show Lot Number - how do you know it is not sorting by date?

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

Hi WarrenBlez,

 

here is a screenshot with and without the date formula in the filter 

 

               Without Date in Filter                                                   With Date in Filter

 

agonciulea_2-1646407874053.pngagonciulea_3-1646407882185.png

 

 

 

Hi @agonciulea ,

What is your data source here ? If it is Excel, then your dates are Text (I see you already have converted several) and the sort is correct. Try this (Note you can only work with record numbers returned from the top filter up to your Delegation limit)

With(
   {
      wList:
      Sort(
         Filter(
            ZZQCLTS,
            StartsWith(QC_LOT_NUMBER,LotSearch.Text),
            StartsWith(PART_NUMBER,PartNumSearch.Text),
            StartsWith(COMMERCIAL_PART_NO, CommerialPartSearch.Text)
         )
      )
   }
   Sort(
      AddColumns(
         Filter(
            wList,
            (IsBlank(DatePicker1.SelectedDate) || DateValue(DATE_MANUFACTURED, "EN-us") = DatePicker1.SelectedDate)
         ),
         "DateSort",
         DateValue(DATE_CREATED)
      ),
      DateSort,
      Descending
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

Hi @WarrenBelz 

 

my data source is SQL

Hi @agonciulea ,

Your dates are Text if you have to convert them with DateValue() - did you try the code I posted?

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

 

agonciulea
Frequent Visitor

Hi @WarrenBelz 

unfortunately the code above did not work. it just errors out.

 

I have been able to determine its a Date filed issue. If i do a Text() , DateValue() or a Startwith() the sort breaks, but if i do a Date with no formating it appears to work correctly.  but now i cant seem to get the datepicker do work correctly or with filter the date. 

Hi @agonciulea ,

As I mentioned, I am not an SQL user, but this document may be of assistance to you.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (6,201)