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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Adding sort options in...
Power Apps
Answered

Adding sort options in table header

(0) ShareShare
ReportReport
Posted on by 716 Moderator

I need some help adding a Sort to a filtered list in a Gallery.

 

I've added an Icon control that both flips as it's used and properly sets a Context variable to DateAscending or DateDescending.

Now that I have the context correct, I need to modify the Items property for the gallery.

 

The current statement is:

 

Switch(
 type,
 "All", Tickets,
 "Requests older than 3 days",
 Filter(
 Tickets,
// Not(datetype in [DateCreated, DateClosed]) &&
 Not(DateCreated in [Text(Today()), Text(DateAdd(Today(), -2)), Text(DateAdd(Today(), -1))] ||
 DateClosed in [Text(Today()), Text(DateAdd(Today(), -2)), Text(DateAdd(Today(), -1))])
 ),
 "Requests opened today", Filter(Tickets, datetype in DateCreated),
 "High Priority", Filter(Tickets, Priority = "High"),
 "Requests closed today", Filter(Tickets, datetype in DateClosed),
 "Search", Filter(Tickets, MySearchText in Subject || MySearchText in Description),
 "My Requests", Filter(Tickets, Owner = User().FullName),
 Filter(Tickets, type in Status)
)

 

I know there are delegation issues but we'll manually control the Tickets table to stay under 2K.

 

Can someone help with adding a sort to this based on DateAscending/DateDescending context? I'm going to add additional sorts as well but I hope I can figure that out after being provided the first solution.

 

Thanks all.

 

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    156,003 Most Valuable Professional on at

    Hi @DCHammer ,

    I have not looked at any of your logic here, but try this structure

    With(
     {
     _Today: Text(Today()), 
     _Tomorrow: Text(DateAdd(Today(), -2)), 
     _NextDay: Text(DateAdd(Today(), -1))
     },
     SortByColumns(
     Filter(
     Tickets,
     type = "All" ||
     Switch(
     type,
     "Requests older than 3 days",
     !(datetype in [DateCreated, DateClosed]) &&
     (
     ![DateCreated in [_Today, _Tomorrow, _NextDay] ||
     DateClosed in [_Today, _Tomorrow, _NextDay]
     ),
     "Requests opened today", 
     datetype in DateCreated,
     "High Priority", 
     Priority = "High",
     "Requests closed today", 
     datetype in DateClosed,
     "Search", 
     MySearchText in Subject || MySearchText in Description,
     "My Requests", 
     Owner = User().FullName, 
     type in Status
     )
     ),
     "YourSortColumn",
     YourSortDirection
     )
    )

     

    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.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • DCHammer Profile Picture
    716 Moderator on at

    I have figured out something that works for most 'type' contexts. If 'type' is On Hold or High Priority, the gallery populates but won't sort. I can't figure out why since the syntax seems to be the same for each.

     

    Apologies for this long ugly section of code. PA does some strange formatting.

     

    Switch(
     type,
     "All",
     SortByColumns(
     Tickets,
     "Created",
     SortOrder
     ),
     "Requests older than 3 days",
     SortByColumns(
     Filter(
     Tickets,
     Not(
     Created in [
     Text(Today()),
     Text(
     DateAdd(
     Today(),
     -2
     )
     ),
     Text(
     DateAdd(
     Today(),
     -1
     )
     )
     ] || field_7 in [
     Text(Today()),
     Text(
     DateAdd(
     Today(),
     -2
     )
     ),
     Text(
     DateAdd(
     Today(),
     -1
     )
     )
     ]
     )
     ),
     "Created",
     SortOrder
     ),
     "Requests opened today",
     SortByColumns(
     Filter(
     Tickets,
     datetype in Created
     ),
     "Created",
     SortOrder
     ),
     "High Priority",
     SortByColumns(
     Filter(
     Tickets,
     field_10 = "High"
     ),
     "Created",
     SortOrder
     ),
     "Requests closed today",
     SortByColumns(
     Filter(
     Tickets,
     datetype in field_7
     ),
     "field_7",
     SortOrder
     ),
     "Search",
     SortByColumns(
     Filter(
     Tickets,
     MySearchText in Subject || MySearchText in Description
     ),
     "Created",
     SortOrder
     ),
     "My Requests",
     SortByColumns(
     Filter(
     Tickets,
     Owner = User().FullName
     ),
     "Created",
     SortOrder
     ),
     "On hold",
     SortByColumns(
     Filter(
     Tickets,
     Priority = "On Hold"
     ),
     "Created",
     SortOrder
     ),
     SortByColumns(
     Filter(
     Tickets,
     type in Status
     ),
     "Created",
     SortOrder
     )
    )
  • Verified answer
    DCHammer Profile Picture
    716 Moderator on at

    I figured it out. I should have known. When the same code does different things depending on the data, IT'S THE DATA.

     

    I'm sorting based on Create which is a system populated value rather than the original CreateDate that was in a spreadsheet from whence the SP list came. When the list was created, it set Create equal to Today() just like it should.

    So the tests that used test data manually created after the list was generated work. In fact it all works, but since the Create date is the same for some data sets so there is zero change between Ascending and Descending.

     

    Thank you for attending Darren's TED Talk for PowerApps Fools. 😄

  • WarrenBelz Profile Picture
    156,003 Most Valuable Professional on at

    @DCHammer ,

    I could have gone "the long way" as well - I was trying to give you something more efficient and should work for you. Have you tried this ?

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 324 Most Valuable Professional

#2
11manish Profile Picture

11manish 193

#3
Valantis Profile Picture

Valantis 138

Last 30 days Overall leaderboard