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 dropdown

(0) ShareShare
ReportReport
Posted on by 76

I have a dropdown that is gettings its values from a collection. There is a code and a name from that collection. How do I sort by code and view by name?

Categories:
I have the same question (0)
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @ryeradio1

    Sort the collection by code as the items of the dropdown. You can choose any field to show in the window of the dropdown from the panel on the right side of the screen. . 

  • Rusk Profile Picture
    1,369 Super User 2024 Season 1 on at

    Hi @ryeradio1 

     

    You can use SortByColumn.  The property you are sorting by does not need to be visible in your dropdown.  Here's an example, with my data source seen on the left (named colTest) and the dropdown on the right.  Example code:

    SortByColumns(colTest,"Code")

    Rusk_0-1678412616963.png

     

    You'll notice "Orange" is first because it has the lowest numeric value in the "Code" column.  You can ensure the correct data is displayed in the dropdown by selecting it under "Value":

    Rusk_1-1678412715554.png

     

  • RyeTeacher Profile Picture
    76 on at

    Thank you for your response. I have created the below collection. When I refer to my dropdown I only have result as an option to choose from. This is my code SortByColumns(collectStudents,"Result",SortOrder.Ascending). This does work, but now it is only showing the code in the dropdown and not the name. Do I have to do something different to display the name instead of the code?

    ClearCollect(
    collectStudents,
    {Result: "All"}
    );

    Collect(
    collectStudents,
    Distinct(
    Contacts,
    'Current Program Level'.Code
    ),
    Distinct(
    Contacts,
    'Current Program Level'.'Grade Level Name'
    )


    )

  • RyeTeacher Profile Picture
    76 on at

    I also only see result as a value. Do you know why I am not seeing the code and the grade name?

     

    ryeradio1_0-1678485499568.png

     

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @ryeradio1 

    You will not be able to accomplish what you want with the formula you are using for the Items property of the dropdown.  The use of Distinct() produces a single column of unique values, for the column named in the function and renames that column Result.   Thus, your formula appends a single column of codes on a single column of names, an illogical construct. 

     

    Instead you need to preserve the table structure that you have and use it as the items property of the dropdown.  Instead of a dropdown, I suggest that you use a combobox control.  An example is shown below

    !!.jpg

    The combobox is sorted on the product code but the product name is used in the search.  The layout chosen is the double one so that your users can see both the name and the product code.  

     

    An alternative would be to use AddColumns{} to add a concatenation of the name and code to your collection.  The screenshot below shows how that would look.  Users could search for a name or code in such a combobox.

    !.jpg

  • RyeTeacher Profile Picture
    76 on at

    Thank you so much! That worked, but it removed my "All" option. How would I go about adding that to my combo box?

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @ryeradio1

    Post your current items property and I will show you how. 

  • RyeTeacher Profile Picture
    76 on at

    My items property is Sort('Grade Levels',Code)

  • RyeTeacher Profile Picture
    76 on at

    This is the code in my grid.

    SortByColumns(
    Search(
    Filter(
    Contacts,
    'Current Program Level'.Code = cbGrade.Selected.Code
    ),
    TextInput1.Text,
    "firstname",
    "lastname"
    ),
    "firstname",
    SortOrder.Ascending
    )

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @ryeradio1 

    Change the placeholder text of your combobox from "Find Items" to "ALL" .  In reality, the value will be blank.

    When filtering a gallery by this combobox, you can use

    Filter(table, IsBlank(Combobox.Selected.Code)||Code=Combobox.Selected.Code)

     

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 April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,045

#2
Valantis Profile Picture

Valantis 675

#3
11manish Profile Picture

11manish 592

Last 30 days Overall leaderboard