How to Sort Power Apps Collection Alphabetically?

Do you know how to sort a collection alphabetically in Power Apps? No worries!

In this Power Apps tutorial, I will explain how to Sort Power Apps Collection alphabetically, including many more like:

  • How to sort Power Apps collection by ascending
  • Power Apps sort collection by descending
  • How to sort Power Apps collection by ascending and descending
  • Working with the Power Apps sort collection by multiple columns

How to Sort Power Apps Collection Alphabetically

Here, we will discuss how to sort a Power Apps collection alphabetically [Ascending].

Example:

1. I manually created a Power Apps collection, i.e., [colEventRegistration]. This collection contains the below Headers/Columns with respective records.

  • Name
  • Company Name
  • Gender
  • Age

Refer to the below image:

Power Apps Sort Collection Alphabetically

2. In Power Apps, there is a Data table control. This data table will sort and display each record from the Power Apps collection based on the “Name” column in ascending order.

Sort Power Apps Collection Alphabetically

To achieve the above example, follow the below-mentioned steps. Such as:

3. To create a Power Apps Collection, go to App’s OnStart property and write the code below:

OnStart = ClearCollect(
    colEventRegistration,
    {
        Name: "John Smith",
        CompanyName: "Buckeyee Furniture",
        Occupation: "Training and development specialist",
        Age: 34,
        Gender: "Female"
    },
    {
        Name: "Emma Reyna",
        CompanyName: "Fox valley CPAs",
        Occupation: "Accountant",
        Age: 32,
        Gender: "Female"
    },
    {
        Name: "Kelven",
        CompanyName: "Bugle Boy",
        Occupation: "Daimond Tracker",
        Age: 44,
        Gender: "Male"
    },
    {
        Name: "Lynee",
        CompanyName: "Specific Appraisals",
        Occupation: "Computer and Information Researcher",
        Age: 40,
        Gender: "Male",
        PhoneNumber: 5360875
    },
    {
        Name: "Steve Mroz",
        CompanyName: "Maxigraphics",
        Occupation: "Graphic Designer",
        Age: 39,
        Gender: "Male",
    },
    {
        Name: "Henrita Mullar",
        CompanyName: "Happy Harry's",
        Occupation: "Customer Suppot Executive",
        Age: 36,
        Gender: "Female"
    }
)

Where,

  • colEventRegistration = Power Apps Collection Name
  • Name, CompanyName, Occupation, Age, Gender = Collection Headers/Columns
  • “John Smith”, “Buckeyee Furniture”, “Training and development specialist” = Collection Records/Rows
How to Sort Power Apps Collection Alphabetically

4. Insert a Data table control and set its Items property to the code below.

Items = Sort(
    colEventRegistration,
    Name
)

Where,

  • Sort() = Power Apps Sort() function helps us to sort the table depending on the formula
  • colEventRegistration = Power Apps Collection Name
  • Name = Collection Column Field
How to sort the Power Apps collection by ascending

5. Click on the Run OnStart under the App object like below.

How to Sort the Power Apps Collection Alphabetically

6. Save, Publish, and Preview the app. The data table displays the sorted records [Event Registration Records] based on the based on “Name” column in ascending order as in the screenshot below.

Sort Power Apps collection by ascending

This is how to sort a Power Apps collection by ascending order.

Power Apps Sort Collection By Descending [Z-A]

Next, I will show you how to sort a Power Apps collection in descending order.

Example:

  1. I will also take the same Power Apps collection [colEventRegistration] for this example.
  2. In Power Apps, there is a Data table control. This data table will sort and display each record from the Power Apps collection based on the “Name” column in descending order.
Power Apps Sort Collection By Descending

To work around this example, follow the below steps:

3. On the Power Apps Screen -> Insert a Data table and set its Items property as:

Items = SortByColumns(
    colEventRegistration,
    "Name",
    SortOrder.Descending
)

Where,

  • SortByColumns() = This function is also used to sort the table depending on the formula
  • “Name” = Power Apps Collection Column Field
  • SortOrder.Descending = Descending order of the Power Apps collection based on the “Name” column
Sort Power Apps Collection By Descending

4. Run OnStart, Save, Publish, and Preview the app. The data table displays the sorted records [Event Registration Records] based on the based on “Name” column in descending order like below.

How to Sort Power Apps Collection By Descending

This is how we can sort a Power Apps collection by descending order.

Power Apps Sort Collection By Ascending And Descending

Let’s discuss sorting a Power Apps collection by ascending and descending order.

Example 1:

1. I have a SharePoint Online List named “Vacation Budget“. This list contains the below fields.

Column NameData Type
DestinationIt is a default single line of a text column, I just renamed it as “Destination”
Expense TypeA single line of text
CategoryChoice
Unit PriceCurrency
Power Apps Sort Collection By Ascending Descending

2. In Power Apps, there is a Sort icon and a Data table. Whenever a user can sort the records either in ascending or descending order based on the only title column [Destination], the data table will display the sorted records.

Sort Power Apps Collection By Ascending Descending

To do so, follow the below steps.

3. On the Power Apps Canvas app -> Select the App object and set its OnStart property as:

OnStart = ClearCollect(
    colVacations,
    'Vacation Budget'
) 

Where,

  • colVacations = Power Apps Collection
  • ‘Vacation Budget’ = SharePoint Online List
How to Power Apps Collection By Ascending Descending

4. Insert a Sort icon and set its OnSelect property as:

OnSelect = Set(
    varColumn,
    "Title"
);
Set(
    varOrder,
    If(
        varOrder = SortOrder.Ascending,
        SortOrder.Descending,
        SortOrder.Ascending
    )
)

Where,

  • Set() = This Power Apps Set() function helps us to set a global variable
  • varColumn = 1st Global Variable Name
  • “Title” = SharePoint Title Field
  • varOrder = 2nd Global Variable Name
  • SortOrder.Descending, SortOrder.Ascending = Sort order can be either ascending or descending
Power Apps Sort a Collection by Ascending And Descending

5. Then, insert a Data table control and set its Items property to the code below.

Items = SortByColumns(
    colVacations,
    varColumn,
    varOrder
)

Where,

  • colVacations = Power Apps Collection
  • varColumn, varOrder = Power Apps Global Variables
Power Apps Sort the Collection by Ascending And Descending

6. Click on the Run OnStart under the App object like below.

Power Apps Sort Collection By Ascending And Descending

7. Save, Publish, and Preview the app. The Data table displays sorted records based on the selecting sort icon [Either ascending or descending] as shown below.

How to Sort Power Apps Collection by Ascending And Descending

Example 2:

  1. I will also take the same SharePoint Online list [Vacation Budget] for this example.
  2. In Power Apps, there are two button controls and a Data table.
  • Sort By A-Z: Whenever the user can sort the record based on the ascending order of the Title [Destination] column, the data table will display the records in ascending order.
  • Sort By Z-A: Whenever the user can sort the record based on the descending order of the Title [Destination] column, the data table will display the records in descending order.

Refer to the below screenshot:

Power Apps Sort a Collection By Ascending Descending

To do so, follow the below steps.

3. On the Power Apps Screen, insert two Button controls and set its OnSelect property codes as:

OnSelect = Set(
    galsort,
    "AZ"                                                      // For Ascending Order
)



OnSelect = Set(
    galsort,
    "ZA"                                                      // For Descending Order
)

Where,

  • galsort = Power Apps Global Variable
  • “AZ”, “ZA” = Variable Values
Sort a Power Apps Collection By Ascending Descending

4. Then, insert a Data table and set its Items property as:

Items = If(
    galsort = "AZ",
    Sort(
        colVacations,
        Title,
        SortOrder.Ascending
    ),
    galsort = "ZA",
    Sort(
        colVacations,
        Title,
        SortOrder.Descending
    )
)

Where,

  • If() = This Power Apps If() function evaluate the unrelated conditions
  • galsort = Power Apps Global Variable
  • colVacations = Power Apps Collection
  • Title = SharePoint Title Field
How to Sort the Power Apps Collection by Ascending And Descending

5. Run Onstart, Save, Publish, and Preview the app. The data table displays sorted records based on the selected button [Sort By A-Z and Sort By Z-A] controls as in the screenshot below.

Power Apps Sort the Collection By Ascending Descending

This is all about the Power Apps sort collection by ascending and descending.

Power Apps Sort Collection By Multiple Columns

Last, we will learn how to sort a Power Apps collection by multiple columns.

Example:

  1. I will also take the same SharePoint Online list [Vacation Budget] for this example.
  2. In Power Apps, there is a Data table. This data table will sort and display each record from the SharePoint Online list based on the two text columns, i.e., [Destination and ExpenseType].

Refer to the below screenshot:

Power Apps Sort Collection By Multiple Columns

To work around this example, follow the below steps.

3. On the Power Apps Screen -> Insert a Data table and set its Items property as:

Items = SortByColumns(
    colVacations,
    "Title",
    SortOrder.Descending,
    "ExpenseType",
    SortOrder.Ascending
)

Where,

  • “Title”, “ExpenseType” = SharePoint List Text Fields
Sort Power Apps Collection By Multiple Columns

4. Run Onstart, Save, Publish, and Preview the app. The data table displays sorted records based on the two text columns, as in the screenshot below.

How to Sort Power Apps Collection by Multiple Columns

This is how to sort a Power Apps collection by multiple columns.

Conclusion

I hope you have a complete idea of how to alphabetically sort the Power Apps collection.

Here, I explained how to sort a Power Apps collection by ascending and how to sort a Power Apps collection by descending.

Also, we discussed the Power Apps sort collection by ascending and descending and how to sort a Power Apps collection by multiple columns.

Also, you may like some more Power Apps tutorials: