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 / Sort sharepoint datatable
Power Apps
Answered

Sort sharepoint datatable

(0) ShareShare
ReportReport
Posted on by 65

Hi!

 

I've got sharepoint list, which is source for DataTable in my PowerApps app. I've used Item property (in DataTable) to create filters for my DataTable (ex. 

If (((Dropdown2_2.DisplayMode = Disabled && Dropdown2_3.DisplayMode = Edit),
Filter(SharePointListSource, ColumnName=Dropdown2_3.Selected.Result)

etc.)

So, that's working fine. 

 

But I've got no clue how to create and add "Sort by date" button. Which be sorting my DataTable by Date(or any other column in DataTable) in all cases, descending/ascending/while being filtered.

Could you help me with this one?

Categories:
  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hey @nottheOther 

     

    You can set the configuration as:

    Button to Sort -> OnSelect -> Set(SortOrder,!SortOrder)

    DataTable -> Items -> If (Dropdown2_2.DisplayMode = Disabled && Dropdown2_3.DisplayMode = Edit,
    Sort(Filter(SharePointListSource, ColumnName=Dropdown2_3.Selected.Result),DateColumnName, If(SortOrder,"Ascending","Descending")))

     

    Hope this Helps!

     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

  • nottheOther Profile Picture
    65 on at

    Hi,

     

    but in this case the only option for sorting is by Date column? Is there an option which I create few buttons/or dropdown list with other columns name for sorting? Ex.

    - sort by date - DateColumnName

    - sort by ID - IDColumnName

    - sort by Status - StatusColumnName

    etc. you get the idea.

    Your solution give me only option for DateColumn. Maybe setting a variable?

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @nottheOther ,

    Could you please share a bit more about your scenario?

    Do you want to sort your Data Table records based on the selected column name () from the Dropdown box?

     

    I have made a test on my side, please consider take a try with the following workaround:

    1. Add a Dropdown control in your app, set the Items property to following:

    ["date", "ID", "Status", ...] // Specify the availble columns from your data source here

    Note: Currently, the SortByColumns function could not be used to sort by a complex type column, e.g. LookUp, Choice, Person, etc.

    2. Set the Items property of the Data Table to following:

    If(
     Dropdown2_2.DisplayMode = Disabled && Dropdown2_3.DisplayMode = Edit,
     If(
     Dropdown1.Selected.Value = "date",
     Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), date, Descending),
     Dropdown1.Selected.Value = "ID",
     Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), ID, Descending),
     Dropdown1.Selected.Value = "Status",
     Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), Status, Descending),
     ...
     ...
     )
    )

    If the Status is a Choice type column in your SP list, please consider modify above formula as below:

    If(
     Dropdown2_2.DisplayMode = Disabled && Dropdown2_3.DisplayMode = Edit,
     If(
     Dropdown1.Selected.Value = "date",
     Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), date, Descending),
     Dropdown1.Selected.Value = "ID",
     Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), ID, Descending),
     Dropdown1.Selected.Value = "Status",
     Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), Status.Value, Descending), // Modify formula here
     ...
     ...,
     )
    )

     

    In addition, you could also consider create each button for these columns you want to sort by in your app, then set the OnSelect property of the "sort by date" button to following:

    Set(SortColumn, "date")

    set the OnSelect property of the "sort by ID" button to following:

    Set(SortColumn, "ID")

    set the OnSelect property of the "sort by Status" button to following:

    Set(SortColumn, "Status")

     

    Then set the Items property of the Data Table to following:

    If(
     Dropdown2_2.DisplayMode = Disabled && Dropdown2_3.DisplayMode = Edit,
     If(
     SortColumn = "date",
     Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), date, Descending),
     SortColumn = "ID",
     Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), ID, Descending),
     SortColumn = "Status",
     Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), Status, Descending),
     ...
     ...,
     Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result) // If SortColumn variable is blank, do not sort your data table
     )
    )

     

    Please consider take a try with above solution, then check if the issue is solved.

     

    Best regards,

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 189 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 139

Last 30 days Overall leaderboard