12 Useful Power Apps Sort Gallery Examples

Recently, I have done a task on how to sort a Gallery control in Power Apps using different real-time scenarios.

In this article, we will see what is Power Apps Sort function, Power Apps SortByColumns function, and many more:

  • Power Apps Sort Gallery By Column
  • Power Apps Sort Gallery By Multiple Columns
  • Power Apps Sort Gallery By Ascending Descending
  • Power Apps Sort Gallery By ID
  • Power Apps Sort Gallery By Newest
  • Power Apps Sort Gallery By Button
  • Power Apps Sort Gallery By Lookup Column
  • Power Apps Sort Gallery By Choice Column
  • Power Apps Sort Gallery By Date
  • Power Apps Sort Gallery By Month
  • Power Apps Sort Gallery By Calculated Field
  • Power Apps Sort and Filter

Power Apps Sort Function

The Power Apps sort function sorts a table based on the user’s formula. In Power Apps, we can sort the table or its items in Ascending or Descending order (User’s choice).

Syntax:

Sort( Table, Formula [, SortOrder ] )

Where,

  • Table – You can specify the table to sort
  • Formula – This formula is evaluated for each record of the table
  • SortOrder – It is optional. You can specify SortOrder.Descending to sort the table in descending order. SortOrder.Ascending is the default value

Power Apps SortByColumns Function

Similarly, the Power Apps SortByColumns function also sorts the table based on single or multiple columns.

Syntax:

SortByColumns( Table, ColumnName1 [, SortOrder1, ColumnName2, SortOrder2, ... ] )

Where,

  • Table -You can specify the table to sort
  • ColumnName(s) – It is required. You can sort column names as strings
  • SortOrder(s) – It is optional, SortOrder.Ascending is the default. If multiple ColumnNames are supplied and the last column must include a SortOrder

Power Apps Sort Gallery By Column

Now, we will discuss how to sort the Power Apps gallery by column using a simple scenario.

Scenario:

I have a SharePoint list named “Vacation Budget” having the below fields.

Column NameData Type
DestinatonIt is a default single line of text
Expense NameA single line of text
CategoryChoice
Total CostNumber
Start DateDate and time
End DateDate and time
power apps sort gallery by column

Now, I would like to sort these SharePoint list records and display the result on the Gallery control, as shown below.

Output:

powerapps gallery sort ascending descending

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

1. On the Power Apps Screen, insert a Gallery control and set its Items property to the code below.

Items = Sort(
    'Vacation Budget',
    Title,
    SortOrder.Ascending
)

Where,

  • ‘Vacation Budget’ = SharePoint Online list
  • Title = SharePoint list title field
sort gallery powerapps

2. Once your app is ready, Save, Publish, and Preview the app. The gallery will display each record from the SharePoint Online list based on the ascending order, as shown below.

powerapps sort gallery

This way, we can sort the Power Apps gallery by column.

Power Apps Sort Gallery By multiple columns

In this example, I will show you how to sort the Power Apps gallery by multiple columns. To do so, select the gallery control and set its Items property to the code below.

Items = SortByColumns(
    'Vacation Budget',
    "Title",
    SortOrder.Descending,
    "TotalCost",
    SortOrder.Ascending
)

Where,

  • “Title”, “TotalCost” = SharePoint list fields
power apps sort gallery by multiple columns

This is how to sort Power Apps gallery control by multiple columns.

Power Apps Sort Gallery By Ascending Descending

Now, I want to sort the Power Apps gallery Alphabetically [Ascending or Descending] using my SharePoint Online list [Vacation Budget].How to Sort Dropdown Choices Alphabetically in Power Apps

Output:

power apps gallery sort

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

1. On the Power Apps Screen, insert a Gallery control and set its Items property as:

Items = Sort(
    'Vacation Budget',
    'Expense Name',                                       //For Ascending Order
    SortOrder.Ascending
)
powerapps gallery sort by ascending descending

2. Similarly, select the gallery control and set its Items property to the code below.

Items = Sort(
    'Vacation Budget',
    'Expense Name',                                        //For Descending Order
    SortOrder.Descending
)
how to sort gallery in powerapps

In the same way, if you want to display sorted gallery records based on the selecting sort icon [Either ascending or descending], you can follow the below steps.

3. On the Power Apps Screen, 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,

  • 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 gallery alphabetically powerapps

4. Finally, select the gallery control and set its Items property as:

Items = 
powerapps sort gallery by column

5. Once your all updates are done, Save, Publish, and Preview the app. The gallery displays sorted records based on the selecting sort icon [Either ascending or descending], as shown below.

power apps sort gallery

This is how we can work with the Power Apps sort gallery by ascending and descending.

Power Apps Sort Gallery By ID

Here, we will see how to sort the Power Apps gallery by ID. In this case, set the Items property of a gallery control using the below code.

Items = SortByColumns(
    'Vacation Budget',
    "ID",
    SortOrder.Descending
)

Where,

  • “ID” = SharePoint ID column
powerapps gallery sort

Power Apps Sort Gallery By Button

In this section, I will discuss how to work with the Power Apps sort gallery by button. To do so, follow the below steps.

1. On the Power Apps Screen, insert a Button control and set its OnSelect property to the code below.

OnSelect = Set(
    varSort,
    Sort(
        'Vacation Budget',
        Title,
        SortOrder.Descending
    )
)

Where,

  • varSort = Power Apps variable name
power apps sort gallery by button

2. Then, select the Gallery control and set its Items property to the code below.

Items = varSort

3. Once you click the button control, the gallery will display sort records in descending order. Have a look at the below screenshot for the output.

powerapps sort ascending descending

This is how we can work with the Power Apps sort gallery by button.

Power Apps Sort Gallery By Newest

In this section, I will explain how to work with the Power Apps sort gallery by newest. For that, select the gallery control and set its Items property as:

Items = SortByColumns(
    'Vacation Budget',
    "StartDate",
    SortOrder.Descending
)

Where,

  • “StartDate” = SharePoint date field
power apps sort gallery by newest

This is how we can sort the Power Apps gallery by newest using descending order.

Power Apps Sort Gallery By Lookup Column

I have a SharePoint list named “Employee Onboarding,” which contains some columns, including the Lookup field [Department].

Input:

powerapps sort gallery by lookup column

Now, I would like to sort the Power Apps gallery by the Lookup column. To do that, insert a Gallery control and set its Items property to the code below.

Items = Sort(
    'Employee Onboarding',
    Department.Value,
    SortOrder.Ascending
)

Where,

  • ‘Employee Onboarding’ = SharePoint Online list
  • Department = SharePoint Lookup field
sort gallery items powerapps

This is way, we can sort the Power Apps gallery by Lookup column.

Power Apps Sort Gallery By Choice Column

Suppose you want to sort the Power Apps gallery by choice column, checkout the below post.

Checkout -> Power Apps Sort Gallery By Choice Column

Power Apps Sort Gallery By Date

Are you want to sort the Power Apps gallery by date, you can follow the below post.

Click Here -> Power Apps Sort Gallery By Date

Power Apps Sort Gallery By Month

In the same way, if you want to sort the Power Apps gallery by Month, check out the tutorial below.

Checkout -> Power Apps Sort Gallery By Month

Power Apps Sort and Filter

In the last section, I will explain how to use the Power Apps sort and filter using a simple scenario.

Scenario:

In Power Apps, there is a Gallery control [It retries data from the 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].

To achieve it, follow the below steps. Such as

1. Select the gallery and write the code below on its Items property:

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

Where,

  • Category = SharePoint choice field value
powerapps sort and filter

This is how we can work with the Power Apps sort and filter.

Some more Power Apps articles you may also like:

I trust this Power Apps tutorial is helpful for you. If you have any requirements for the Power Apps sort gallery, follow this post until the end, where I explain different examples with real-time scenarios.

  • >