How to Sort Power Apps Gallery By ID?

Do you know how to sort Power Apps Gallery by ID? No problem!

In this Power Apps tutorial, I will explain how to sort Power Apps Gallery by ID from SharePoint List.

Also, we will see how to work with Power Apps Sort Gallery By ID [from SharePoint Custom Column] with various examples.

How to Sort Power Apps Gallery By ID

I will take two examples to sort Power Apps Gallery By ID here.

Example – 1:

In this scenario, we will see how to sort the gallery record using the SharePoint ID field. It’s so simple to achieve this.

Setup a SharePoint List

I have a SharePoint Online list named TSInfo Attachments. This list has various columns with different data types:

ColumnDatatype
IDNumber
TitleSingle line of text
Attachment TypesChoice [PPT, PDF. Microsoft Document, Excel]
Attachment CostsCurrency
Also, this SharePoint list has some records like below.
How to Sort Power Apps Gallery By ID

Sort Gallery By ID in Power Apps

1. In Power Apps, there is a Text input control and a Gallery control. All the gallery records are retrieved from the SharePoint list.

2. When the search box is empty, the gallery will appear with all the SharePoint list records.

3. When a user enters any file name in the search box, the gallery filters according to user search-related records in descending order (based on ID values), as seen below.

Power Apps sort by id
Power Apps sort by id

4. To work around this, we will use the below formula on the gallery’s Items property:

Items = SortByColumns(
    Filter(
        'TSInfo Attachments',
        StartsWith(
            Title,
            txtSearchFile.Text
        )
    ),
    "ID",
    SortOrder.Descending
)

Where,

  1. TSInfo Attachments‘ = SharePoint list name
  2. StartsWith = This Power Apps function helps test whether a text string begins with another. To know more details about this post, go through this complete tutorial: Power Apps StartsWith and EndsWith Functions
  3. Title = Single line of text field that the user will search in the search box
  4. txtSearchFile = Text input control name where the user will search the file name
  5. “ID” = Specify the SharePoint ID field name that you want to sort
PowerApps sort by id

5. Save and preview the app. When you enter a search term (like PowerApps) into the search box, the gallery will filter and display the results according to the ID field (in descending order).

This is how to work with Power Apps sort by ID.

Example – 2:

In this scenario, we will see how to sort the Power Apps gallery by ID from the SharePoint list [Custom ID Column].

Setup a SharePoint List

The screenshot below represents a SharePoint list named Employee Onboarding. This list has these many columns:

ColumnDatatype
Employee IDNumber
Employee NameSingle line of text
DepartmentChoice [HR, IT, FINANCE, MARKETING]
PictureImage

Also, this list has these many below records. Refer to the image below.

Power Apps Sort Gallery By ID

Power Apps Sort Gallery By ID

1. In Power Apps, there is a Vertical Gallery control with all the records from the SharePoint list.

2. All gallery records are arranged by Employee ID in descending order, as seen in the screen below.

PowerApps Sort Gallery By ID

3. To work with it, select the gallery control and set its Items property to the code below:

Items = Sort(
    'Employee Onboarding',
    'Employee ID',
    SortOrder.Descending
)

Where,

  1. ‘Employee Onboarding’ = SharePoint list name
  2. ‘Employee ID’ = SharePoint Number Field [Custom column]
Power Apps sort gallery by id

4. Once we save and preview the app, the gallery will appear in descending order with the SharePoint Employee ID column.

This is how to work with Power Apps Sort Gallery By ID.

Conclusion

I hope you got an idea about how to sort Power Apps Gallery by ID from the SharePoint List.

Also, in this article, we learned how to work with Power Apps Sort Gallery By ID [from SharePoint Custom Column] with various examples.

Also, you may like some more Power Apps tutorials:

>