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 / How to Sort by Choice ...
Power Apps
Answered

How to Sort by Choice Column Values in specific order

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have a filter button that will filter data in a specific order.

 

OnSelect I have this:

ClearCollect(col_Engineers,SortByColumns(EngineersV2,"Total_x0020_Assigned",SortOrder.Descending));

So I grab all my engineers, and sort them by the number of assigned cases.

 

Depending on which filter (check box) I have selected, it will show me those records.

For example, if I choose to show all Available engineers, the code is:

If(
 l_available,
 ClearCollect(
 col_Engineers,
 Filter(
 col_Engineers,
 EngineerQueueStatus.Value = "Available" || 'EngineerQueueStatus'.Value = "Out of Queue Soon"
 )
 )
);

If I want to see who is in the office:

If(
 l_inoffice,
 ClearCollect(
 col_Engineers,
 Filter(
 col_Engineers,
 EngineerQueueStatus.Value <> "Unavailable"
 )
 )
);

 

The office one is the one i want to change.

I want to add some code to this piece, so that instead of sorting by total number of cases which is what the collection is set at, I would like to override that ONLY for this piece (inoffice).

I want to filter out the collection for ANYONE that has a queuestatus value of anything except Unavailable.

Then instead of showing me everyone in the office sorted by total cases, I want to sort it by the values in that Choice column.

So for me, I want it to sort like this..

Engineers in this order:

Available

Out of Queue Soon

Out of Queue

In Queue Soon

 

I keep running into errors.

I tried to add a SortByColumn into that inoffice piece of code, but it kept throwing up on me.

 

Categories:
  • lardo5150 Profile Picture
    Microsoft Employee on at

    I may have come up with a better way to do this with an if statement.

    How would I setup the sorting the way I want it, when defining the collection.

    example:

    ClearCollect(col_Engineers,SortByColumns(EngineersV2,"Total_x0020_Assigned",SortOrder.Descending));

    I have tried this a few ways, but I keep geting an error for SortByColumns.

  • Verified answer
    lardo5150 Profile Picture
    Microsoft Employee on at

    I resolved this:

     

    f(l_inoffice=true,
     ClearCollect(
     col_Engineers,SortByColumns(
     AddColumns(
     EngineersV2,"EngineerQueueStatus_value",EngineerQueueStatus.Value),
     "EngineerQueueStatus_value",["Available","Out of Queue Soon",
     "Out of Queue","In Queue Soon","In Queue Later","Assign No Cases",
     "Assign No Crits","Assign Only Crits"]
     )
     ),
     ClearCollect(col_Engineers,SortByColumns(EngineersV2,"Total_x0020_Assigned",SortOrder.Descending
     )
     )
    );

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 383 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 356

#3
WarrenBelz Profile Picture

WarrenBelz 232 Most Valuable Professional

Last 30 days Overall leaderboard