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 / Using Multiple Sort Or...
Power Apps
Unanswered

Using Multiple Sort Orders in a Gallery

(0) ShareShare
ReportReport
Posted on by 94

Hi all,

 

I have a gallery connected to a database table with the following columns:

ChildName
Center
Date
State

And I have implemented SortByColumns() in the gallery which sorts on search results (if any)

SortByColumns(Search('[dbo].[tblTardyStatus]_1', TextSearchBox1.Text, "ChildName", "Center","Date","State"),"State", ["New", "Absent", "Absent unexcused", "Late", "Late unexcused", "On-time"])

It sorts a filtered result based on the Search() parameters (text matching any of the 4 columns) and then sorts it by the "State" column with a custom order which is

["New", "Absent", "Absent unexcused", "Late", "Late unexcused", "On-time"]

The issue I'm having is then sorting the results in alphabetical order according to the ChildName column. I have by adding two new arguments to the SortByColumns like displayed on the sort function page for powerapps

SortByColumns(Search('[dbo].[tblTardyStatus]_1', TextSearchBox1.Text, "ChildName", "Center","Date","State"),"State", ["New", "Absent", "Absent unexcused", "Late", "Late unexcused", "On-time"], "ChildName", Ascending)

The issue is that it returns the error "SortByColumns has some invalid arguments"

 

Thanks for any help

Categories:
I have the same question (0)
  • v-micsh-msft Profile Picture
    Microsoft Employee on at

    Hi @ChrisC,

     

    The syntax for the SortByColumns is as below:

    First usage:

    SortByColumnsTableColumnName1 [, SortOrder1ColumnName2SortOrder2, ... ] )

    Second usage:

    SortByColumnsTableColumnNameSortOrderTable )

     

    Per your formula, you are trying to combine those two usage into one, which is not supported.

    To workaround this, take a try to add a nested SortByColumns funtion.

    Formula should be:

    SortByColumns(
     SortByColumns(
     Search('[dbo].[tblTardyStatus]_1', TextSearchBox1.Text, "ChildName", "Center","Date","State"),
     "State", 
     ["New", "Absent", "Absent unexcused", "Late", "Late unexcused", "On-time"]), 

    "ChildName", Ascending)

    Regards,

    Michael

  • ChrisC Profile Picture
    94 on at

    Hi @v-micsh-msft,

     

    It doesn't seem to be sorting by childname still but I cannot see why your solution wouldn't work..

    I also tried reversing the nest order to see if that would do it but unfortunately not. Thank you for the insight though, I will try and come up with a solution based on this

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I'm seeing the same results as @ChrisC here- A Custom Sort + Sort by Alpha does not seem to be working. Does anyone know how to do a custom sort where a group of columns are presented first, then the remaining columns sorted alphabetical in ascending order? 

    Example:

    SortByColumns(
     SortByColumns(
     colData,
     "CHAR_NAME",
     [
     "THING1",
     "OTHERTHING1",
     "THING2",
     "OTHERTHING2",
     "ETC"
     ]
     ),
     "CHAR_NAME",
     Ascending
    )

     Thanks

  • WarrenBelz Profile Picture
    154,799 Most Valuable Professional on at

    Hi @ericonline ,

    Try this

    Sort(
     SortByColumns(
     colData,
     "CHAR_NAME",
     [
     "THING1",
     "OTHERTHING1",
     "THING2",
     "OTHERTHING2",
     "ETC"
     ]
     ),
     CHAR_NAME,
     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.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @WarrenBelz . Thanks for the idea. This sorting just eliminates the custom sort (in the square brackets) and puts the whole list in alpha. 

    I'm looking for custom sort up top, then alpha after.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @v-micsh-msft . Thanks for the idea. This results in losing the custom sort (everything in the square brackets). The list is sorted by alphanumeric only. 

    I need the custom sort on top of the list and alphabetic after the custom sort.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 530

#2
WarrenBelz Profile Picture

WarrenBelz 459 Most Valuable Professional

#3
Haque Profile Picture

Haque 314

Last 30 days Overall leaderboard