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 a Collection Whil...
Power Apps
Answered

Sort a Collection While Excluding the First Item from the Sort So It Remains at Top of the List?

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

(Canvas App) Is there a way to sort a collection while maintaining the first item at the top of the list? I have a list of users in the collection but manipulated the collection so that "Sort a User" appears at the top. Is there a way to sort the collection and keep "Sort a User" at the top?

I am building a canvas app and I have a drop down that is populated from a collection which is populated from a sharepoint list of the user names. I have manipulated my collection so that "Select a User" appears first in the list. The screen's OnVisible property is set with the following code which populates a collection from a sharepoint list of users.

// Retrieve ALL users that have been assigned to ANY deal 
ClearCollect( collUsersAssigned, 'Assigned-Users' );
// Create new collection from selected Deal ID
ClearCollect( collUsersAssignedSelectedID, Filter( collUsersAssigned, Deal_x002d_Request_x002d_ID = galleryLHAssignResources.Selected.'DI-ID' ) );

Next I add the following code so that "Select a User" appears first in the drop down.

// Use a collection to pre-populate User dropdown with a default 'Select a User' option
ClearCollect( myDropdownOptionsUsers, { 'Full-Name': "Select a User"} );
Collect( myDropdownOptionsUsers, 'Available-Resources'.'Full-Name' );

The first item in the drop down menu is always Select a User. I can successfully sort the list items in the drop down using the code below.

Sort( myDropdownOptionsUsers.'Full-Name', 'Full-Name', Ascending )

Unfortunately it also sorts 'Select a User' into the list alphabetically but I need it to remain the first item in the drop down. Is there a way to sort the collection and keep "Sort a User" at the top?

Categories:
I have the same question (0)
  • cds Profile Picture
    1,001 on at

    Collect( Sort(mydrodownoptionusers, 'Full Name', ascending) , 'AvailableResource'.'full-name')

  • Verified answer
    WarrenBelz Profile Picture
    155,491 Most Valuable Professional on at

    Hi @Anonymous ,

    Try this

    ClearCollect(
     myDropdownOptionsUsers,
     {'Full-Name': "Select a User"}
    );
    
    Collect(
     myDropdownOptionsUsers, 
     Sort(
     'Available-Resources',
     ' Full Name'
     ).'Full-Name'
    )

     

    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

    @cds Thank you for your quick response. 

    Collect( Sort(myDropdownOptionsUsers, 'Full-Name', Ascending), 'Available-Resources'.'Full-Name' )

    Unfortunately the code below did not work. I received the following error message.
    "Behavior function in a non-behavior property. You cannot use this property to change values elsewhere in the app."

  • cds Profile Picture
    1,001 on at

    Try sorting it when you initially collect that collection 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thank you @WarrenBelz - This is the solution!

    ClearCollect(
    myDropdownOptionsUsers,
    {'Full-Name': "Select a User"}
    );

    Collect(
    myDropdownOptionsUsers,
    Sort(
    'Available-Resources'.'Full-Name',
    ' Full Name'
    ).'Full-Name'
    )

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 414

#2
Valantis Profile Picture

Valantis 387

#3
timl Profile Picture

timl 344 Super User 2026 Season 1

Last 30 days Overall leaderboard