How to Sort Data Table in Power Apps [4 Easy Ways]

Sorting data in a Power Apps data table has been easy. Users can easily sort the data table either directly, alphabetically, or by column headings.

In this Power Apps tutorial, I will show you what are the 4 various ways to sort data table in Power Apps like:

  • Power Apps Sort Data table Manually
  • How to sort Data table by Power Apps button
  • Sort Data table by column heading in Power Apps
  • Power Apps Sort Data table by multiple columns

Power Apps Sort Data table

To sort Power Apps data table, refer to the below example.

Example,

I have a SharePoint list [ACGH Products] with various columns:

Column NameData type
Product NameTitle
CategoryChoice [“Electronics,” “Kitchen Appliances,” “Home”]
PriceCurrency
CountryLookup
Power Apps Sort Data table

The screenshot below represents a Power Apps Data table, including a Sort icon. When a user clicks on the sort icon, the data table will be sorted by its Product column, either in ascending or descending order, as shown below.

Sort Power Apps Data table

Follow the below steps to achieve this:

Step 1: On the Power Apps screen, insert a Sort icon and set its OnSelect property as:

UpdateContext(
    {
        varSortProduct: "Title",
        ProductSortDescending: !ProductSortDescending
    }
)

Where,

  1. varSortProduct = Provide the variable name
  2. Title = SharePoint list title column
  3. ProductSortDescending = Provide the variable name
Sort Data table in Power Apps

Step 2: Insert a Gallery control and set its Items property:

SortByColumns(
    'ACGH Products',
    "Title",
    If(
        ProductSortDescending,
        SortOrder.Ascending,
        SortOrder.Descending
    )
)

Where,

  1. ACGH Products = SharePoint list name
How to sort Data table in Power Apps

Step 3: Now, Save, Publish, and Preview your app. Once the user clicks on the sort icon, the Data table Product column will be sorted in ascending or descending order.

How to sort Power Apps Data table

This is how we can sort the data table using the sort icon in Power Apps.

Power Apps Sort Data table By Button

Let me show you how to sort the data table using a Power Apps button control.

Example:

The Power Apps screen has two button controls with a Data table.

  • Button 1 [Price: High to Low]= When a user clicks this button, the price column in the data table is sorted from high to low.
  • Button 2 [Price: Low to High] = When a user clicks this button, the price column in the data table is sorted from low to high.
Power Apps Sort Data table by a button control

Let’s follow the below steps to achieve this:

Step 1: On the Power Apps screen, insert a Button control [High-Low] and set its OnSelect property to:

Set(varPrice,"Descending")

Where,

  1. varPrice = Provide the variable name
Sort Data table by a button control in Power Apps

Step 2: On the Power Apps screen, insert another Button control [Low-High] and set its OnSelect property to:

Set(varPrice,"Ascending")
Sort Power Apps Data table by a button control

Step 3: Insert a Gallery control and set its Items property to:

SortByColumns(
    'ACGH Products',
    "Price",
    If(
        varPrice = "Descending",
        SortOrder.Descending,
        SortOrder.Ascending
    )
)

Where,

  1. ACGH Products = Above SharePoint list name
  2. varPrice = Provide the variable name
How to Sort Power Apps Data table by a button control

Step 4: Save, Publish, and Preview your app. Once the user clicks on a button control, the Power Apps data table is sorted by a price column from highest to lowest or lowest to highest based on that.

How to sort Data table by a button control in Power Apps

This way, we can sort the data table using a button control in Power Apps.

Power Apps sort Data table by Column Heading

Here, we will learn how to sort the data table by column heading in Power Apps.

I have a SharePoint list [Loan Approval] with various columns like:

Column NameData type
User NameTitle
Loan TypeChoice [“Home Loan,” “Car Loan, “Gold Loan]
Credit ScoreNumber
CountryLookup
Power Apps sort Data table by column heading

The Power Apps Data table is connected to the above SharePoint list.

I have added a Sort icon to each data table header. By clicking on any sort icon in a specific header, the data table will be sorted either in ascending or descending order according to that column.

Sort Data table by column heading in Power Apps

Follow the below steps to achieve this:

Step 1: On the Power Apps screen, insert a Data table and set its Items property to:

'Loan Approval'

Where,

  1. Loan Approval = Above SharePoint list name
Sort Power Apps Data table by column heading

Step 2: Insert a Sort icon for each column heading, as shown below:

How to sort Power Apps Data table by column heading

Step 3: Select each Sort icon and set its OnSelect property to:

User Name = UpdateContext({varSortPriority:"Title",SortDescending:!SortDescending}) 

Loan Type =
UpdateContext({varSortPriority:"LoanType",SortDescending:!SortDescending})

Credit Score = 
UpdateContext({varSortPriority:"CreditScore",SortDescending:!SortDescending})

Country = 
UpdateContext({varSortPriority:"Country",SortDescending:!SortDescending})

Where,

  1. varSortPriority = Provide the variable name
How to sort Data table by column heading in Power Apps

Step 4: Select a Gallery control and set its OnSelect property to:

If(
    varSortPriority = "Title",
    Sort(
        'Loan Approval',
        Title,
        If(
            SortDescending,
            SortOrder.Ascending,
            SortOrder.Descending
        )
    ),
    If(
        varSortPriority = "Loan Type",
        Sort(
            'Loan Approval',
            'Loan Type'.Value,
            If(
                SortDescending,
                SortOrder.Ascending,
                SortOrder.Descending
            )
        ),
        If(
            varSortPriority = "Credit Score",
            Sort(
                'Loan Approval',
                'Credit Score',
                If(
                    SortDescending,
                    SortOrder.Ascending,
                    SortOrder.Descending
                )
            ),
            If(
                varSortPriority = "Country",
                Sort(
                    'Loan Approval',
                    Country.Value,
                    If(
                        SortDescending,
                        SortOrder.Ascending,
                        SortOrder.Descending
                    )
                ),
                'Loan Approval'
            )
        )
    )
)

Where,

  1. Loan Approval = Above SharePoint list name
  2. varSortPriority = Variable name
  3. SortDescending = Variable name
Sort Data table by column heading Power Apps

Step 5: Save, Publish, and Preview the app. Once the user clicks on each sort icon of a particular data table header, the data table will be sorted in an ascending or descending order based on that particular column.

Power Apps Sort Data table by a column heading

This way, we can sort the data table by column heading in Power Apps.

Power Apps Sort Data table by Multiple Columns

Let’s see how we can sort the Power Apps data table using multiple columns.

Example:

The Power Apps data table is connected to the above SharePoint list [Loan Approval]. The 1st column is sorted in ascending order, and the other column is sorted in descending order.

Power Apps sort data table by multiple columns

Follow the below steps to achieve this:

Step 1: On the Power Apps screen, insert a Data table and set its OnSelect property to:

SortByColumns(
    'Loan Approval',
    "Title",
    SortOrder.Ascending,
    "CreditScore",
    SortOrder.Descending
)

Where,

  1. Loan Approval = Above SharePoint list name
  2. Title = SharePoint list title column
  3. CreditScore = SharePoint list number column name
Sort data table by multiple columns in Power Apps

Step 2: Now, we can see that the Power Apps data table’s two columns will be sorted in ascending order.

How to sort Power Apps data table by multiple columns

This is how we can sort the Power Apps data table by multiple columns.

Also, you may like:

Conclusion

This Power Apps tutorial taught you how to sort the Power Apps Data table manually and how to sort the data table using a button control.

Moreover, I have shown you how to sort the data table by column heading in Power Apps and sort the Data table by multiple columns in Power Apps with various examples.