Sort Power Apps Data Table Based On SharePoint Choice Column

If you are using a Data table in Power Apps, you might need to sort its data according to various requirements, such as sorting the table in ascending, descending, or alphabetical order.

In Power Apps, it’s quite easy to sort data alphabetically or based on any column name (e.g., Employee Name), where the first character of the name is used to sort.

But what if you want to sort the Power Apps Data table by a SharePoint choice field? Yes, I also learned this while working on a client task, where he instructed me to sort the Power Apps data table information in descending order based on SharePoint choice values.

In this article, I will tell you how to sort Power Apps Data table based on SharePoint Choice column in two different methods. Such as:

  • Add and sort a new column on the Power Apps Data table Items property (Method-1)
  • Add and sort a new column in a Power Apps Collection (Method-2)

Sort Power Apps Data Table Based On SharePoint Choice Column

Here, I have a SharePoint list named IT Hardware Issues that contains various columns (like Text, Multiline text, Date time). Among them is a choice field called Device Type, which includes some choices like Laptop, Monitor, Printer, etc.

Sort Power Apps Data Table Based On SharePoint Choice Values

In Power Apps, there is a Data table control with all the SharePoint list data. I want to sort the Power Apps Data table based on the SharePoint Choice value (Device Type).

Sort Power Apps Data Table Based On a SharePoint Choice Column

To work around this, we can use any of the two methods below.

Method – 1: [Add a New Column & Sort On Power Apps Data Table Items Property]

1. Select the Power Apps Data table control and set its Items property to the code below:

SortByColumns(
    AddColumns(
        'IT Hardware Issues',
        DeviceTypeValue,
        'Device Type'.Value
    ),
    "DeviceTypeValue",
    SortOrder.Descending
)

Where,

  • AddColumns() = Power Apps AddColumns function adds a column to a table. To learn more, refer to this complete tutorial link.
  • DeviceTypeValue = New Column Name
  • DeviceType = SharePoint Choice Field Name
  • “DeviceTypeValue” = Ensure to enclose the new column name with an inverted comma (“”)
  • SortOrder.Descending = Provide the sort order that you want, either in ascending or descending
Sort PowerApps Data Table Based On SharePoint Choice Column

2. Save, publish, and preview the app. The Power Apps Data table has been sorted in descending order by the SharePoint Choice values.

Method – 2: [Create a Collection, Add a New Column & Sort Power Apps Data Table]

The second alternative method for sorting the Power Apps Data table by SharePoint Choice value is to create a new collection and call that collection from the Data table’s Items property.

1. Let’s create a Power Apps collection on the App’s OnStart property. You can also create the collection on a Button’s OnSelect or the Screen’s OnVisible property.

ClearCollect(
    colDeviceType,
    SortByColumns(
        AddColumns(
            'IT Hardware Issues',
            DeviceTypeValue,
  'Device Type'.Value
        ),
        "DeviceTypeValue",SortOrder.Descending
    )
)

Where,

colDeviceType = Power Apps Collection Name

powerapps sort by choice column

2. Select the Data table control and set its Items property as:

colDeviceType
How to Sort Power Apps Data Table Based On SharePoint Choice Column

3. As we have created the collection on App’s OnStart property, we need to run it (App -> … Elipses -> Run OnStart). Then, you can see the data table has sorted by the choice field in descending order.

Sort Data table in Power Apps Based On SharePoint Choice Value

These are the two different approaches to sorting the data table in Power Apps based on the SharePoint Choice field value. Method 1 is best for best practices and to reduce code and time. Method 2 is the best approach if you face any Power Apps delegation warning issues.

I hope you found this article useful.

Also, you may like some more Power Apps articles:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App