Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Adding sort options in table header

(0) ShareShare
ReportReport
Posted on by 714 Super User 2025 Season 1

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:
  • WarrenBelz Profile Picture
    146,596 Most Valuable Professional on at
    Re: Adding sort options in table header

    @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 ?

  • Verified answer
    DCHammer Profile Picture
    714 Super User 2025 Season 1 on at
    Re: Adding sort options in table header

    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. 😄

  • DCHammer Profile Picture
    714 Super User 2025 Season 1 on at
    Re: Adding sort options in table header

    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
     )
    )
  • WarrenBelz Profile Picture
    146,596 Most Valuable Professional on at
    Re: Adding sort options in table header

    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

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,596 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,928 Most Valuable Professional

Leaderboard