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

Sort a Gallery tem by Time

Hi, I want to sort a gallery items by time Ascending or Descending (Date_Time column in Sharepoint List). Pls help me.

Ex: 26/12/2021 14:00

     26/12/2021  08:30

     26/12/2021 11:00

     26/12/2021 09:15

5 REPLIES 5
WarrenBelz
Super User
Super User

Hi @BuiDucNghia ,

Put a button on the screen with

UpdateContext({varSortOrder:!varSortOrder})

then your gallery Items

Sort(
   YouSPListName,
   YourDateTimeField,
   If(
      varSortOrder,
      Descending,
      Ascending
   )
)

 

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 

Thanks @WarrenBelz 

I  want to sort a gallery by time the same day as pic attachment.

IMG-5256.jpg

My code in Gallery Items: If(
IsBlank(colSelectedDate), //if gallery not select, filter Gallery is Today
SortByColumns(
Filter(
colLichTuan, txtSearchLichTuan.Text in DateValue(Text(ThoiGian)),
//ThoiGian: DateTime Column in Sharepoint List
DateTimeValue(Text(ThoiGian, ShortDateTime24)) >= Today(),
DateTimeValue(Text(ThoiGian, ShortDateTime24)) < DateAdd(Today(),1,Days)
), "ThoiGian", Ascending // want to sort by time here as Pic.
),
WeekdayGallery_1.Selected.LichHop_grp
)

@BuiDucNghia ,

I have not addressed your If logic as it is not clear to me, but for the rest if you want to sort by Time on the date selected

If(
   IsBlank(colSelectedDate), //if gallery not select, filter Gallery is Today
   SortByColumns(
      Filter(
         AddColumns(
            colLichTuan,
            "TimeSort",
            Text(ThoiGian,"hh:mm")
         ), 			
         txtSearchLichTuan.Text in Text(ThoiGian,"dd/mm/yyyy) ||
         Text(ThoiGian,"dd/mm/yyyy") = Text(Today(),"dd/mm/yyyy")
      ), 
      "TimeSort",
      If(
         varSortOrder,	  
         Descending,
         Ascending 
      )
   ),
   WeekdayGallery_1.Selected.LichHop_grp
)

 

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

Thanks for your help, but still not work 😞

@BuiDucNghia ,

"Not work" does not really help me - are you getting any errors - if so what are they. 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (1,735)