How to Sort Combo Box Items in Power Apps

Do you know how to sort the number of items in a Power Apps Combo box control? If not, this Power Apps tutorial will show you how to sort and keep items in a combo box control in an informative order. This methodology will also be used in a variety of scenarios. For example:

  • Power Apps combo box sort items
  • Power Apps combo box items in descending order
  • Power Apps combo box sort distinct
  • Power Apps sort combo box alphabetically
  • Power Apps combo box sort choices
  • Power Apps combo box sort selectedItems
  • Sort gallery by combo box Power Apps
  • Power Apps combo box sort with filter
  • Power Apps combo box sort year
  • Power Apps combo box sort by date

Power Apps sort function

In Power Apps, there is a function Sort() that sorts a table using a formula. The formula is applied to each table record, and the results are used to sort the table. The formula must produce a number, string, or Boolean value; it cannot produce a table or record.

Sorting is the process of arranging data into meaningful order in order to examine it more effectively. The syntax for this function is:

Sort( Table, Expression [, SortOrder ] )

Where,

  1. Table: The required data source or table, which will be sorted
  2. Expression: The required expression is applied to each table record, and the results are used to sort the table. Columns within the table can be referenced.
  3. SortOrder: It is optional where we can set the order as ascending or descending. By default, the items are sorted in ascending order. It is specified as SortOrder.Descending to sort the table in descending order or SortOrder.Ascending to sort the table in ascending order.

Now, we will see how to use this Sort() function within the Power Apps combo box control.

Power Apps combo box sort items

In this section, we will see how to sort the number of items within the Power Apps combo box control. Suppose we have a SharePoint list named Projects that has such columns as Project Title and HandleBy (a person field) like below:

Power Apps combo box sort items
Power Apps combo box sort items

We created a blank canvas app in Power Apps and linked it to the above SharePoint list. Now, we’ll create a combo box control in Power Apps and sort the item’s properties using sort(), resulting in sorted items. The following steps are:

  • On the Power Apps screen, add a combo box control. Go to +Insert tab > Input > Combo box.
  • Next, select the combo box control and insert the below expression in the Items property to display the ‘Project Title’ items as the combo box items.
Items = Projects.'Project Title'

Where,

  1. Projects: The name of the SharePoint list.
  2. ‘Project Title’: The name of the SharePoint column.

Now we can see the items listed in the Power Apps Combo box control below:

Combo box sort items Power Apps
Combo box sort items Power Apps

To sort the above items within the Power Apps combo box control, replace the below expression within the Items property.

Items = Sort(Projects, 'Project Title', Ascending)
Sorting items Power Apps combo box
Sorting items Power Apps combo box

Let’s take a look at this app, and we can see that the items are sorted in ascending order, as shown below:

Sorting items Power Apps combo box control
Sorting items Power Apps combo box control

This is how to sort the items within the Power Apps combo box control.

Also read: Power Apps combo box with Office 365 users

Power Apps combo box items in descending order

Here, we will see how to organize the combo box items in descending order in Power Apps. Similarly, if you want to keep the above items in descending order, replace the below expression on the combo box’s Items property.

Items = Sort(Projects, 'Project Title',Descending)

Once the above expression is applied, we can see the items will be listed in descending order like below:

Power Apps combo box items descending order
Power Apps combo box items in descending order

This is how to set the items in descending order within the Power Apps combo box control.

Power Apps combo box sort distinct

In this section, we’ll look at how to sort the distinct values within the Power Apps combo box control. Assume there are some duplicates or repeated values within a Power Apps combo box control that we created, such as the following:

Power Apps combo box sort distinct
Power Apps combo box sort distinct

Let’s remove the duplicate values from the above combo box control. As a result, it will display only distinct values and sort those distinct items in descending order. For this, the following steps are:

  • Select the combo box control.
  • Insert the below expression on the combo box’s Items property.
Items = Sort(Distinct(Products, Title),Result,Descending)

Where,

  1. Products: The name of the SharePoint data source.
  2. Title: The name of the SharePoint column.
Distinct and Sort in Power Apps Combo box
Distinct and Sort in Power Apps Combo box

Let’s take a look at the above combo box, which contains only distinct values sorted in descending order, as shown below:

Sort and Distinct in Power Apps Combo Box
Sort and Distinct in Power Apps Combo Box

This is how to Sort and Distinct items in the Power Apps Combo Box.

Check out: How to Reset Power Apps Combo Box

Power Apps sort combo box alphabetically

Here, we will see how to sort combo box items alphabetically. Suppose, we have built a collection on the screen’s OnVisible property like below:

Power Apps sort combo box alphabetically
Power Apps sort combo box alphabetically

The collection will be displayed only when the screen is visible.

Power Apps sort the combo box alphabetically
Power Apps sort the combo box alphabetically

Next, we will build a combo box control using the above collection in the Combo box’s Items property like below:

Items = CollCity.City

Where,

  1. CollCity: The name of the Collection
  2. City: The name of the collection header
Power Apps sort combo box control in alphabetically
Power Apps sort combo box control alphabetically

Let’s sort the above collection items alphabetically in the Power Apps combo box control. To do this, the following steps are:

  • Select the above combo box and insert the below expression in the Items property.
Items = Sort(CollCity, City)

Since we did not specify the order, it will sort the items in ascending order, as below:

Sort Power Apps combo box alphabetically
Sort Power Apps combo box alphabetically

This is how to Sort the Power Apps combo box items alphabetically.

Power Apps combo box sort choices

Here, we will see how to sort choices within the Power Apps combo box control. Suppose, we have a SharePoint list that has a choice column like the below:

Power Apps combo box sort choices
Power Apps combo box sort choices

On the Power Apps, we will build a combo box control using the above choice column. For this, insert the below expression on the Items property of the combo box control.

Items = Choices('Job Openings'.JobLocation)

Where ‘Job Openings’ is the name of the SharePoint data source and JobLocation is the name of the SharePoint choice column.

Power Apps combo box sort SharePoint choices
Power Apps combo box sort SharePoint choices

To sort the above choices in the Power Apps combo box control, insert the below expression in the Items property.

Items = SortByColumns(Choices('Job Openings'.JobLocation),"Value")

Or, you can use the below formula to sort the choices inside the combo box control in the Items property:

Items = Sort(Choices('Job Openings'.JobLocation),Value)

Now, we can see all the choices will be sorted in the combo box control like below:

Power Apps combo box sort the SharePoint choices
Power Apps combo box sort the SharePoint choices

This is how to sort the SharePoint choices within the Power Apps combo box control.

Have a look: Power Apps Cascading Dropdown Control

Power Apps combo box sorts user

Here, we will see how to sort the user or Office365Users within the Power Apps combo box control.

To work with this scenario, we need to connect the app with the Office365Users. Navigate to Add Data > Search Office365Users > Select. We can see it will be connected to the Power Apps.

power apps combo box sort user
power apps combo box sort user

Let’s build a combo box control within the Power Apps screen. Then insert the below expression on the Items property to receive all the Office365Users within the Power Apps Combo box control.

Items = Office365Users.SearchUser()
power apps combo box sort users
power apps combo box sort users

Now, we’ll sort the users listed above in descending order. Insert the following expression into the Items property of the combo box control to accomplish this.

Items = Sort(Office365Users.SearchUser(),DisplayName,Descending)
power apps combo box sort Offiec365Users
power apps combo box sort Offiec365Users

This is how to sort the Users or Office365Users within the Power Apps Combo Box control.

Power Apps combo box sort by date

We’ll look at how to use the Power Apps combo box sorted by date in this section. That is, we will create a combo box control with a SharePoint date column that will display the date in sorted order.

Assume we have a specific SharePoint list that has a date column like the below:

Power Apps combo box order by date
Power Apps combo box order by date

Let’s use the above date column to create a combo box on the Power Apps screen. However, because the Combo box does not support the date column, so it will not display any date values within the combo box control, as shown below.

Power Apps combo box sort by date
Power Apps combo box sort by date

To display the date column, we need to convert this into text format. So replace the combo box’s Items property with the below expression.

Items = Distinct(Sort(Products.DeliverDate,DeliverDate),Text(DeliverDate,"[$-en-US]dd/mm/yyyy")).Result

Where,

  1. Products: The name of the SharePoint data source
  2. DeliverDate: The name of the date column
  3. dd/mm/yyyy: The format of the date column

The result is sorted when the formula is applied to the combo box’s Items property and the dates are converted to text format.

How to sort dates in a Power Apps combo box
How to sort dates in a Power Apps combo box

This is how to sort the dates in a Power Apps combo box.

Check out: How to Filter Power Apps Dropdown Control

Power Apps combo box sort year

Similarly, we will see how to sort years within the Power Apps combo box control in this section. Assume we have another date and time column in a SharePoint list that contains the following random values:

Power Apps combo box sort year
Power Apps combo box sort year

Let us build a combo box control that will display only the year from the date column in descending order. To work with this scenario, the following steps are:

  • On the Power Apps screen, add a combo box control.
  • To display only the years from the date column, enter the following expression into the combo box’s Items property.
Items = Distinct(Sort(Products.OrderDate,OrderDate,Descending),Text(OrderDate,"[$-en-US]yyyy")).Result

Where,

  1. Products: The name of the SharePoint data source.
  2. OrderDate: The name of SharePoint’s date column
  3. Descending: Set the order property i.e., Ascending or Descending
  4. “[$-en-US]yyyy”: The format of the date column
Power Apps combo box sort years
Power Apps combo box sort years

Now preview the combo box control and we can see it will display only the years that were retrieved from the date column.

Sorting years in Power Apps Combo Box
Sorting years in Power Apps Combo Box

This is how to sort years in the Power Apps Combo Box.

Power Apps combo box sort selectedItems

Here, we will see how to sort the selected items in the Power Apps combo box control. Suppose, we have a SharePoint list named Projects having 2 columns such as Project Title (Single line text) and Project Location(choice column)

Power Apps combo box sort selectedItems
Power Apps combo box sort selectedItems

Now we’ll create a combo box control containing all the options from the above list. When a user selects more than one item, the items are saved in ascending order in the SharePoint list.

To work with this scenario, the following steps are:

  • On the Power Apps screen, we will add a text input to insert the project’s title.
  • Then add a combo box control and insert the below expression on the Items property of the combo box to display the choices.
Items = Choices(Projects.'Project Location')
  • Next, add a button control to that screen and insert the below expression on the button’s OnSelect property to save the data to the SharePoint list as well as save the selected items in ascending order.
OnSelect = Patch(Projects,Defaults(Projects),{'Project Title': Txt_ProjectTitle.Text,'Project Location':Sort(Cmb_Location.SelectedItems,Text(Value),Ascending)})

Where,

  1. Projects: The name of the SharePoint list.
  2. ‘Project Title’, ‘Project Location’: The name of the SharePoint column.
  3. Txt_ProjectTitle: The name of the text input.
  4. Cmb_Location: The name of the combo box control.
Power Apps Combo Box Sort Selected Items
Power Apps Combo Box Sort Selected Items

Now, save and publish the app. Play the app in preview mode. Let’s insert some data in both controls (Project Title- Project1, Project Location- Nice, Atlanta, Mexico).

Sorting the Combobox selectedItems
Sorting the Combobox selected items

Now we’ll create a combo box control that contains all of the options from the previous list. When a user selects more than one item, the items are saved in ascending order in the SharePoint list.

Combo Box selected items sort in Power Apps
Combo Box selected items to sort in Power Apps

This is how to sort the combo box selected items within the Power Apps.

Check out: How to Work With Power Apps Dropdown Blank Values

Sort gallery by combo box Power Apps or Power Apps combo box sort with filter

Here we will see how to sort and filter a gallery based on the Power Apps combo box selection. Suppose, we have a SharePoint list named Events which has a title and location (a choice field) column like the below:

Power Apps combo box sort with filter
Power Apps combo box sort with filter

We will create a Power Apps combo box control using the above choice field as per the requirement. We will also create a Power Apps gallery to display the data. That is when the user selects an item from the combo box, the data filters and appears in the gallery in either descending or ascending order.

To achieve this need, the following steps are:

  • Build a combo box control on the Power Apps screen and insert the below expression on the Items property to display the choices.
Items = Choices(Events.Location)
Sort gallery by combo box Power Apps
Sort gallery by combo box Power Apps
  • Add a gallery control to the screen and insert the below query on the gallery’s Items property to filter the data based on the combo box selection as well as sorted data.
Items = SortByColumns(Filter(Events, Location.Value = Location_Cmb.Selected.Value),"Title",Ascending)

Where,

  1. Events: The name of the SharePoint data source
  2. Location: The name of the choice column
  3. Location_Cmb: The name of the combo box control
Sort the gallery based on combo box Power Apps
Sort the gallery based on combo box Power Apps

Let’s preview the app and select any item from the combo box (ex- Phonix), we can see the filtered items will display in ascending order like below:

Power Apps combo box sort and filter
Power Apps combo box sort and filter

This is how to sort and filter a Power Apps gallery based on combo box selection.

Also, have a look at the below Power Apps Tutorials:

Conclusion

This Power Apps Tutorial taught us all about Power Apps sort() and how to use it within the Power Apps combo box control. In addition, we covered the following topics while using the sort() function in the combo box control. Examples include:

  • Power Apps sort function
  • Power Apps combo box sort items
  • Power Apps combo box items in descending order
  • Power Apps combo box sort distinct
  • Power Apps sort combo box alphabetically
  • Power Apps combo box sort choices
  • power apps combo box sort user
  • Power Apps combo box order by date
  • Power Apps combo box sort year
  • Power Apps combo box sort selectedItems
  • Power Apps combo box sort with filter or Sort gallery by combo box Power Apps
>