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 / Issue with Sorting Gal...
Power Apps
Answered

Issue with Sorting Gallery Items by Due Date in PowerApps

(0) ShareShare
ReportReport
Posted on by

Hello everyone,

I'm currently facing an issue in PowerApps related to sorting gallery items by due date. I have a gallery that displays items from a SharePoint list. Each item has a due date associated with it. I wanted to provide a sorting feature for users to sort the items in the gallery by due date when they click a button.

Here's what I've tried so far:

  1. I added a button named "Sort by Due Date" with the following OnSelect property: UpdateContext({ SortByDueDate: true }).

  2. I modified the gallery's Items property with the following code to include filtering conditions and sorting based on the due date:
    Filter(
    'List Building List',
    Len(CampaignFilter.Text) = 0 || StartsWith(Title, CampaignFilter.Text),
    Len(Namefilter.Text) = 0 || StartsWith('Requestor Name', Namefilter.Text),
    Len(Progressfilter.Selected.Value) = 0 || Progress.Value = Progressfilter.Selected.Value,
    Len(ComboBox1.Selected.Value) = 0 || 'Service requested' = ComboBox1.Selected.Value
    )

    I have the Due Date displayed in the gallery using a text label with the text property: "Due Date: " & ThisItem.'Due Date'.

    However, despite my efforts, when I click the "Sort by Due Date" button, the items are not sorting by due date as expected. I have encountered errors related to SortByColumns and If functions, and I'm struggling to find a solution.

    I'd greatly appreciate any guidance or insights on how to properly implement the sorting functionality by due date in my PowerApps gallery.

    Thank you in advance for your assistance!

    Additional Information:

    • The Due Date column is a date and time format in the SharePoint list.
    • The gallery is successfully displaying items and filtering is working as intended.
    • I've been exploring different approaches, but I'm unsure about the correct syntax to use for sorting based on the Due Date field.



Categories:
I have the same question (0)
  • Rajkumar_M Profile Picture
    3,741 Super User 2025 Season 2 on at

    Hi @Anonymous 

     

    Try this

     

    If you use variable SortByDueDate

     

    SortByColumns(
    Filter(
    'List Building List',
    Len(CampaignFilter.Text) = 0 || StartsWith(Title, CampaignFilter.Text),
    Len(Namefilter.Text) = 0 || StartsWith('Requestor Name', Namefilter.Text),
    Len(Progressfilter.Selected.Value) = 0 || Progress.Value = Progressfilter.Selected.Value,
    Len(ComboBox1.Selected.Value) = 0 || 'Service requested' = ComboBox1.Selected.Value
    ),
    'Due Date',
    If(SortByDueDate, SortOrder.Ascending, SortOrder.Descending)
    )

    (Or)

     

    SortByColumns(
    Filter(
    'List Building List',
    Len(CampaignFilter.Text) = 0 || StartsWith(Title, CampaignFilter.Text),
    Len(Namefilter.Text) = 0 || StartsWith('Requestor Name', Namefilter.Text),
    Len(Progressfilter.Selected.Value) = 0 || Progress.Value = Progressfilter.Selected.Value,
    Len(ComboBox1.Selected.Value) = 0 || 'Service requested' = ComboBox1.Selected.Value
    ),
    'Due Date',
    SortOrder.Ascending
    )

     

    Reference link : Solved: Sort by date and time - Power Platform Community (microsoft.com)

     

    Thanks!

     

    If my response has been helpful in resolving your issue, I kindly request that you consider clicking "Accept as solution" and "giving it a thumbs up" as a token of appreciation.

  • Community Power Platform Member Profile Picture
    on at

    So I have tried both and have the same errors:

    PaulHajjar_0-1691766080972.pngPaulHajjar_1-1691766095982.png

     

  • v-qiaqi@microsoft.com Profile Picture
    on at

    Hi @Anonymous,

    SortByColumns() need to refer to column name using a pair of double quotes, which is "":

    SortByColumns(Filter(
    'List Building List',
    Len(CampaignFilter.Text) = 0 || StartsWith(Title, CampaignFilter.Text),
    Len(Namefilter.Text) = 0 || StartsWith('Requestor Name', Namefilter.Text),
    Len(Progressfilter.Selected.Value) = 0 || Progress.Value = Progressfilter.Selected.Value,
    Len(ComboBox1.Selected.Value) = 0 || 'Service requested' = ComboBox1.Selected.Value
    ),"DueDate",If(SortByDueDate,SortOrder.Ascending))

     

  • Community Power Platform Member Profile Picture
    on at

    Hello Qi Thank you for your response, I have pasted the formula you gave me in my Items property of the gallery and here was the result:

    PaulHajjar_0-1692000354666.png

    Here are the issues based on pwerapps monitor:

    PaulHajjar_1-1692000408301.png

    PaulHajjar_2-1692000421566.png

    Thats it. Also I have an icon on the top of my screen that I want to use as the sort by due date icon. For now I tried an approach and here is the property of the onselect: If(
    varSortOrder = "asc",
    Set(varSortOrder, "desc"),
    Set(varSortOrder, "asc")
    )
    Thanks in advance!!

  • Verified answer
    v-qiaqi@microsoft.com Profile Picture
    on at

    Hi @Anonymous,

    Confused.....

    I refer to SortByDueDate because you create this variable, you need to replace it with the real variable name in your scenario.

     

    In addition, to make the sort order by another variable, please check as below.

    1). add an sort icon and set its OnSelect as:

    UpdateContext({SortDescending1: !SortDescending1})

    vqiaqimsft_0-1692000931129.png

     

    2). Set the Gallery Items property:

    SortByColumns(Filter(
    'List Building List',
    Len(CampaignFilter.Text) = 0 || StartsWith(Title, CampaignFilter.Text),
    Len(Namefilter.Text) = 0 || StartsWith('Requestor Name', Namefilter.Text),
    Len(Progressfilter.Selected.Value) = 0 || Progress.Value = Progressfilter.Selected.Value,
    Len(ComboBox1.Selected.Value) = 0 || 'Service requested' = ComboBox1.Selected.Value
    ),"DueDate",If(SortDescending1, SortOrder.Descending, SortOrder.Ascending))

     

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 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard