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 / SortByColumns mixed so...
Power Apps
Answered

SortByColumns mixed sortorder conditions

(0) ShareShare
ReportReport
Posted on by 18

Hello,

 

I am attempting to use SortByColumns in a Gallery in the following way (see code snippet below) - I want to first sort by Status, but it is not sufficient from a business standpoint to sort by ascending or descending order. Thus, I specified the order I would like the Status field sorted by defining values in a comma separated list.

 

Then, I want to subsort by timestamp (a date field) descending. End state, I would ideally end up with all 'Unclaimed' items first, subsorted from most recent to least recent timestamp, then all 'Claimed' items, subsorted from most recent to least recent timestamp, and so on. 

 

Power Apps throws a syntax error with the below formula, saying that the SortByColumns function has invalid arguments, but by my eyes I am following the syntax outlined in the documentation (https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-sort).

 

Is this a limitation of the SortByColumns function, that it cannot combine two kinds of sortorder methods (i.e. one specifying your values in a list, and one simply ascending/descending)? Or am I missing something?

 

If it is a limitation, am I able to use Sort to accomplish this somehow or has anyone crafted a way to code around this?

 

Thanks to anyone for any help you can provide!

Alex

 

SortByColumns(

<Table>,

"Status",
[
"Unclaimed",
"Claimed",
"Pending",
"Completed",
"Cancelled"
],

"Timestamp",

Ascending

)

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

    Hi @ahaugstad ,

    The syntax needs a sort order for each

    SortByColumns(
     <Table>,
     "Status",
     Ascending,
     "Unclaimed",
     Ascending,,
     "Claimed",
     Ascending,
     "Pending",
     Ascending,,
     "Completed",
     Ascending,
     "Cancelled"
     Ascending,,
     "Timestamp",
     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.

  • ahaugstad Profile Picture
    18 on at

    Hi Warren,

     

    Thank you for the quick reply! This is still throwing a syntax error for me - error text "The specified column does not exist", starting at "Unclaimed".

     

    To clarify, the list of values I included in my code snippet (["Unclaimed", "Claimed", etc.]) are allowed values for the "Status" field.

     

    Does that change things at all? 

     

    Thanks again for the help,

    Alex

  • Verified answer
    ahaugstad Profile Picture
    18 on at

    I was able to resolve this - there is another post that addresses a similar example:

    https://powerusers.microsoft.com/t5/Building-Power-Apps/Using-Multiple-Sort-Orders-in-a-Gallery/td-p/61894 


    If it helps others to see my example through, to accomplish my end goal (which was having the order be all 'Unclaimed' items first, subsorted from most recent to least recent timestamp, then all 'Claimed' items, subsorted from most recent to least recent timestamp, etc.), I implemented the below:

     

    SortByColumns(SortByColumns(<Table>,"Timestamp",Descending),"Status",["Unclaimed", "Claimed", "Pending", "Completed", "Cancelled"])

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

    Hi @ahaugstad ,

    Glad you got it working. Timezone issues prevented me responding to your last post (5:30am now in Australia)

  • ahaugstad Profile Picture
    18 on at

    Hi Warren, no problem at all - your first reply got me thinking in the right direction. Thanks so much for the assistance!

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 505

#2
WarrenBelz Profile Picture

WarrenBelz 502 Most Valuable Professional

#3
Haque Profile Picture

Haque 324

Last 30 days Overall leaderboard