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 Apps
Answered

Sort not sorting

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have two collections that I want sorted but nothing seems to be working. I am building the collections based on other collections. The first collection is a list of customers with a 'Name' column. The second collection is of contact names (and other info) and also contains the customer name. I want to sort first by 'Customer' and the 'Name' so all contacts are in alpha order grouped by customer, which is also in alpha order.

 

These are my two Sort calls:

Sort(
 expCustCol,
 Name
);
Sort(
 Sort(
 expContCol,
 Customer
 ),
 Name
);

I then pass these to a Flow to create CSV files. I check the collections right after the sorts and then don't change. 

 

I tried with the column names in quotes too, but no luck. I also tried switching tnhe Sort with SortByColumns abd no change. 

 

Any ideas what I am missing?

Categories:
I have the same question (0)
  • cha_cha Profile Picture
    4,932 Moderator on at

    Hello @Anonymous 

     

    To use multiple columns for sorting, you have to use the SortByColumns function.

    https://learn.microsoft.com/en-us/power-platform/power-fx/reference/function-sort

     

    Code would be something like this:

    SortByColumns( expContCol, "Customer", SortOrder.Ascending, "Name",SortOrder.Ascending )

     If i misunderstood your order, try this:

    SortByColumns( expContCol, "Name", SortOrder.Ascending, "Customer",SortOrder.Ascending )
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @cha_cha according to examples, Sort can work as I have it, but I had SortByColumns first and it didn't sort either. I have them as Sort because the SortBy didn't work, so tried this. 

  • TheRobRush Profile Picture
    11,128 Moderator on at

    Just to make it easier to figure out I would place two vertical galleries on your screen and wokr out the syntax there first, but should be

    SortByColums(expContCol, "Customer", SortOrder.Ascending, "Name", SortOrder.Ascending)
    

    and

    SortByColumns(expCustCol,"Name", SortOrder.Ascending)
  • TheRobRush Profile Picture
    11,128 Moderator on at

    Oops we crossed haha

  • cha_cha Profile Picture
    4,932 Moderator on at

    Hello @Anonymous 

     

    Maybe there is a type issue on your code? That's the most probable reason I can think of if the sorting is not working. This might be a type on the code or the data like extra spaces.

  • Verified answer
    cha_cha Profile Picture
    4,932 Moderator on at

    Ah!

    You need to assign the sorted information to a collection.

    ClearCollect(COL_ABC,Sort(
     Sort(
     expContCol,
     Customer
     ),
     Name
    );)

     

    Then Export COL_ABC.

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    thank you.

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 392 Most Valuable Professional

#2
11manish Profile Picture

11manish 136 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 109 Super User 2026 Season 2

Last 30 days Overall leaderboard