How to Sort Power Apps Gallery by Choice Column?

This Microsoft Power Apps tutorial will explain all the information about how to sort a Power Apps gallery by choice column, including:

  • Sort Power Apps Gallery by Collection Choice Field
  • How to Sort Power Apps Gallery by SharePoint List Choice Field
  • Working with Sorting and Filtering Power Apps Gallery by SharePoint Choice Field

Sort Power Apps Gallery by Choice Column [From Collection]

Here, we will discuss how to sort the Power Apps gallery by collection choice field with a simple example.

Example:

I have created a Power Apps collection, i.e., [colFurniture]. This collection contains the following fields:

  • Furniture ID
  • Furniture Name
  • Furniture Type
sort power apps gallery by choice column

Now, I want to sort and display the Power Apps collection on a Gallery control based on the collection choice field [Furniture Type] as in the Screenshot below.

sort power apps gallery by choice field

To work around this example, follow the below-mentioned steps. Such as:

1. Create Power Apps Canvas app -> Select App object [From left navigation] -> Set its OnStart property to the code below.

OnStart = ClearCollect(
    colFurniture,
    {
        FurnitureID: "DC001",
        FurnitureName: "Dining Tables",
        FurnitureType: "Dining & Kitchen"
    },
    {
        FurnitureID: "DC002",
        FurnitureName: "Media Storage",
        FurnitureType: "Living"
    },
    {
        FurnitureID: "DC003",
        FurnitureName: "Bedroom Sets",
        FurnitureType: "Bedroom"
    },
    {
        FurnitureID: "DC004",
        FurnitureName: "Office Suits",
        FurnitureType: "Office"
    },
    {
        FurnitureID: "DC005",
        FurnitureName: "Backyard Play",
        FurnitureType: "Outdoor"
    },
    {
        FurnitureID: "DC006",
        FurnitureName: "Dining Storage",
        FurnitureType: "Dining & Kitchen"
    },
    {
        FurnitureID: "DC007",
        FurnitureName: "Kitchen Storage",
        FurnitureType: "Dining & Kitchen"
    },
    {
        FurnitureID: "DC008",
        FurnitureName: "TV Stand",
        FurnitureType: "Living"
    }
)

Where,

  • colFurniture = Power Apps Collection Name
  • Furniture ID, Furniture Name, Furniture Type = Collection Headers/Columns
  • “DC001”, “Dining Tables”, “Dining & Kitchen” = Collections Rows/Records
how to sort power apps gallery by choice column

2. Then, click on the Apps’s Run OnStart button to get the collection [Variables -> Collections -> View Table] as shown below.

how to sort power apps gallery by choice field

3. Now, go to the Power Apps Screen -> Insert a Gallery control and set its Items property as:

Items = Sort(
    colFurniture,
    FurnitureType,
    SortOrder.Ascending
)

Where,

  • Sort() = This Power Apps Sort() function is used to sort the table based on a formula
  • colFurniture = Collection Name
  • FurnitureType = Collection Choice Field
how to sort a power apps gallery by choice column

4. Save, Publish, and Preview the app. The Power Apps gallery will sort and display each record based on the collection choice field, as shown below.

how to sort power apps gallery using choice field

This is how to sort a Power Apps gallery by collection choice field.

Sort Power Apps Gallery by SharePoint Choice Field

Next, we will see how to sort a Power Apps gallery by SharePoint choice field with a simple scenario.

Scenario:

I have a SharePoint Online list named “Travel Requests” and inside this, I have added different columns with various data types, including the choice field [Airline] as shown below.

sort a power apps gallery by sharepoint choice column

In Power Apps, I have a Gallery control connected to my SharePoint list. I want to sort the Power Apps gallery control by SharePoint choice field [Airline] as in the screenshot below.

sort power apps gallery by sharepoint choice field

To achieve it, follow the below steps.

1. Open Power Apps canvas app -> Connect to the respective SharePoint Online list [Travel requests] like below.

how to sort power apps gallery by sharepoint choice field

2. On the Power Apps Screen -> Insert a Horizontal gallery control and set its Items property to the code below.

Items = Sort(
    'Travel Requests',
    Airline.Value
)

Where,

  • ‘Travel Requests’ = SharePoint Online List
  • Airline = SharePoint Choice field
how to sort power apps gallery by sharepoint choice column

3. Save, Publish, and Preview the app. The gallery will sort and display each record from a SharePoint list based on the choice field, as in the screenshot below.

how to sort a power apps gallery by sharepoint choice column

Scenario 2:

I will also use the SharePoint list [Travel Requests] for this scenario. Now, I want to search and sort the gallery based on the choice field [Airline].

Whenever the user searches for any choice field record value using the text input control, the gallery sorts, filters, and displays the records based on the choice field value, as in the screenshot below.

how to sort a power apps gallery by sharepoint choice field

To do so, follow the below steps. Such as:

1. insert a Text input control [txt_Airline] on the Power Apps Screen. Then, insert a Gallery control and set its Items property as:

Items = Sort(
    Filter(
        'Travel Requests',
        txt_Airline.Text in Airline.Value
    ),
    Airline.Value
)

Where,

  • txt_Airline = Power Apps Text input name
  • Airline = SharePoint choice field
how to sort  power apps gallery using sharepoint choice field

2. Save, publish, and Preview the app. The gallery will sort, filter, and display each record from the SharePoint choice field based on the searching value on the text input like below.

sort  power apps gallery using sharepoint choice field

This is how to sort a Power Apps gallery by SharePoint choice field.

Conclusion

This Power Apps tutorial taught us how to sort a Power Apps gallery by choice field [from collection]. Then, we saw sorting a Power Apps gallery control by SharePoint list choice field.

Last, we covered how to sort and filter a Power Apps gallery control by SharePoint list choice field.

You may also like the following tutorials:

>