How to Sort Data Table in Power Apps?

    When you are working with the Power Apps data table, you may want to sort the Power Apps data table. Thankfully, there are two Power Apps functions, i.e., [Sort() and SortByColumn()], to sort the Power Apps data table records.

    In this article, I will explain how to sort data table in Power Apps with real-time examples. Also, we will discuss how to sort and filter the Power Apps data table.

    How to Sort Data Table in Power Apps

    While working with the Power Apps Data table control, we usually need to sort the data table per our requirements. Now, I will show you how to sort the Power Apps data table in different scenarios. Such as:

    1. How to Sort Power Apps Data Table Alphabetically [A-Z or Z-A]
    2. Sort Power Apps Data Table By Ascending and Descending
    3. How to Sort and Filter Power Apps Data Table

    Sort Power Apps Data Table Alphabetically

    I have a Power Apps data table that retrieves all the records from my Power Apps collection [colEventRegistration], as in the screenshot below.

    Sort and filter Power Apps data table control

    Now, I would like to sort the Power Apps data table Alphabetically [Ascending or Descending]. Have a look at the below output.

    How to sort PowerApps Data table

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

    1. Open Power Apps with your respective Microsoft credentials -> Create a Blank canvas app -> Select App object and set its OnStart property to 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"
        },
        {
            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 Data Table in Power Apps

    2. On the Power Apps Screen -> 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 text field
    How to Sort a Data Table in Power Apps

    3. Once your app is ready, Save, Publish, and Preview the app. The data table sorts and displays each record from the collection based on the ascending order [A-Z] like below.

    How to Sort the Data Table in Power Apps

    4. Also, if you want to sort the Power Apps data table in descending order [Z-A] then select the Data table and set its Items property as:

    Items = SortByColumns(
        colEventRegistration,
        "Name",
        SortOrder.Descending
    )
    How to Sort Power Apps Data Table Alphabetically

    5. Look at the screenshot below to see how we can sort the Power Apps data table records in descending order.

    This way, we can sort the Power Apps data table alphabetically.

    How to Sort a Power Apps Data Table Alphabetically

    Sort Power Apps Data Table By Ascending and Descending

    Here, I will show you how to sort the Power Apps data table by ascending and descending with a simple example.

    Example:

    I have a SharePoint Online list named “Vacation Budget” and this list contains the below fields.

    Input:

    Column NameData Type
    DestinationIt is a default single line of text
    Expense NameA single line of text
    CategoryChoice
    Estimated CostCurrency
    Number Of PeopleNumber
    How to sort and filter the Power Apps data table

    In Power Apps, there is a Sort icon and a Data table [It retrieves all the records from the SharePoint list]. Whenever the user clicks on the sort icon, it will sort the data table records in either ascending or descending order based on the SharePoint list title field [Destination].

    Output:

    How to Sort Data Table in PowerApps

    To do so, follow the below steps.

    1. On the Power Apps 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
    Sort Data Table in Power Apps

    2. Next, insert a Sort icon and set its OnSelect property to the code below.

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

    Where,

    • 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
    Sort a Data Table in Power Apps

    3. Now, insert a Data table control and set its Items property as:

    Items = SortByColumns(
        colVacations,
        varColumn,
        varOrder
    )

    Where,

    • colVacations = Power Apps Collection
    • varColumn, varOrder = Power Apps Global Variables
    Sort Power Apps Data Table

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

    How to Sort a Data Table in PowerApps

    How to Sort and Filter Power Apps Data Table

    Let’s see how to sort and filter the Power Apps data table with a simple scenario.

    Scenario:

    In Power Apps, there is a Data table control [It retries data from SharePoint list]. I want to sort the data table in Ascending order and filter the gallery based on the SharePoint choice field value [Category is equal to Entertainment].

    Have a look at the screenshot below for the output:

    How to sort and filter PowerApps Data table

    To achieve this, follow the below steps. Such as:

    1. On the Power Apps Screen -> Insert a Data table control and set its Items property to the code below.

    Items = Sort(
        Filter(
            'Vacation Budget',
            Category.Value = "Entertainment"
        ),
        Title,
        SortOrder.Ascending
    )

    Where,

    • Sort() = Power Apps Sort() function helps us to sort the table depending on the formula
    • Filter() = This function is used to find a set of records that match one or more criteria and to discard those that don’t
    • ‘Vacation Budget’ = SharePoint Online list
    • Category, Title = SharePoint list fields
    Sort and filter the Power Apps data table

    2. Once your app is ready, Save, Publish, and Preview the app. The Power Apps data table sorts and filters each record from the SharePoint Online list based on the choice field. Have a look at the below screenshot for the output.

    This way, we can sort and filter the Power Apps data table.

    Sort and filter PowerApps Data table

    This Power Apps tutorial taught us all about Sorting a Power Apps data table in different ways. If you have any requirements to work with the Sorting a Power Apps data table, you can follow the above ways.

    Also, rRefer to some more below Power Apps posts:

    >