Do you know what is the Sort and Sort Gallery in Power Apps? In this Power Apps tutorial, we will read all the details about Power Apps Sort Gallery and its various examples.
Also, we will cover these below topics:
- Power Apps sort gallery Or Power Apps gallery sort ascending descending
- Power Apps sort gallery items
- Power Apps sort gallery by choice column
- Power Apps sort gallery by date
- Power Apps sort gallery by label
- Power Apps sort gallery based on dropdown
- Power Apps gallery sort and filter
- Power Apps sort gallery by date and time
- Power Apps sort and search gallery
- Power Apps gallery sort by newest
- Power Apps gallery sort distinct
- Power Apps gallery sort get row number
- Power Apps gallery sort by multiple columns
- Power Apps sort gallery by calculated field
- Power Apps sort gallery by checkbox
Power Apps Sort Function
- Power Apps Sort is a type of function that helps to sort a table depending on the formula that is provided by the user. Moreover, another Power Apps function, i.e. SortByColumns, helps to sort the table based upon single or multiple columns.
- We can sort the table or its items in Ascending or Descending order (user’s choice) in Power Apps.
Power Apps sort gallery or Power Apps gallery sort ascending descending
Whenever a user sorts the records in a Power Apps Gallery control, it is known as Power Apps Sort Gallery or Sort ascending descending in Power Apps Gallery. Check out the below simple scenario.
- The below screenshot represents a SharePoint Document Library named Book Images. This library has all the default columns like Name, Modified, Modified By, etc. Also, it has some images as shown in the below screenshot.

- In Power Apps, there is a Gallery control with a Text input control and a Sort icon. Now, what I would like to do is, that a user will search the book and the gallery will filter and display the search-related information.
- Also, whenever a user will click on the sort icon, then the gallery filtered items will appear in ascending order, and vice versa when the user will again tap on the same sort icon.

- To achieve this, select the Sort icon and apply the below code on its OnSelect property as:
OnSelect = UpdateContext({ctxSortDescending: !ctxSortDescending})
Where,
ctxSortDescending = Context variable name

- Next, select the gallery control and set its Items property to the below formula:
Items = SortByColumns(
Search(
[@'Book Images'],
txtSearchBook.Text,
"{Name}"
),
"{Name}",
If(
ctxSortDescending,
Descending,
Ascending
)
)
Where,
- ‘Book Images’ = SharePoint Document Library Name
- txtSearchBook = Text input control name where a user can search the book name
- “{Name}” = This is the library column name

- Save and preview the app. Once you will search any book inside the search box, you can see the gallery will filter and display those search-related records only. To sort (ascending or descending) the gallery items, you can tap on the sort icon as per your need.
This explains all about the sort ascending descending in Power Apps Gallery control.
Read: PowerApps Dropdown Gallery + Examples
Power Apps sort gallery items
Suppose in Power Apps, you want to sort the gallery items based upon any of the SharePoint fields (let’s say Title). Refer to the scenario below to do so.
- There is a SharePoint list named Employee Onboarding and it has the fields below:
- Employee Name = By default, this is a Title column (with a Single line of text data type). To look better, I just renamed it to Employee Name.
- Employee Last Name = This is also a single line of text data type field
- Employee ID = It is a Number Data type where a user will enter the Employee ID value
- Department = This is a Choice column data type where a user will choose the department.

- Next, in the app, there is a Gallery control that displays all the items from the SharePoint list. Now, I would like to sort (in ascending order) these items based on the SharePoint Title field.
- To workaround this, select the gallery and apply the code below on its Items property as:
Items = SortByColumns(
'Employee Onboarding',
"Title",
Ascending
)
Where,
- ‘Employee Onboarding‘ = SharePoint list name
- “Title” = Specify the SharePoint list field name that you want to sort. Instead of the Title, you can take any field that you want to sort in the gallery.
- Ascending = Mention the order either you want to view the field values in ascending or descending order.

This is how to work with sort gallery items in Power Apps.
Also, Read: PowerApps Search Function + How to use with example
Power Apps sort gallery by choice column
Next comes how we can sort the Power Apps Gallery control by the SharePoint Choice column. To achieve it easily, refer to the below simple scenario.
- As you can see, there is a SharePoint list named Products. This list has different columns with different data types. Such as:
- ID = By default, this is an ID column (with Number data type) of the list.
- Title = By default, this is a Single line of text column.
- Vendor = It is a Choice field where a user can select the product vendor.
- Customer Name = This is a Single line of text field
- Quantity = Number field where a user can enter the product quantity
- Sales Date = This is a Date and time field
- Status = A Choice field where a user can view their product status like Submitted, Approved, Pending, Rejected, etc.
- I would like to sort the Power Apps Gallery control based upon this SharePoint Choice field i.e. Status.

- To achieve this, we will use the Power Apps AddColumns function inside the code. Apply the code below on Gallery’s Items property as:
Items = SortByColumns(
AddColumns(
Products,
"Status_value",
Status.Value
),
"Status_value",
[
"Submitted",
"Pending"
]
)
Where,
- AddColumns = PowerApps AddColumns is a type of function that helps to add a column to a table. To read more details about AddColumns function, PowerApps AddColumns Function with Examples
- Products = SharePoint List name
- “Status_value” = Provide a new unique column name
- Status = Specify the SharePoint Choice column that you want to sort. As it is a Choice field, that’s why we need to specify it with a .Value parameter.
- “Submitted“, “Pending” = A column of values to be used for sorting purposes.

- Finally, select the label from the gallery section and then set its Text property to the below code:
Text = ThisItem.Status_value
Status_value = Specify the new column name that we have added in the previous code

This is how to work with the sort gallery by choice column in Power Apps.
Checkout: Power Apps Search SharePoint List Examples
Power Apps sort gallery by date
Do you want to sort the Power Apps Gallery control by using the SharePoint Date field? If so, then how you will do so far? Check out the below scenario to achieve this.
- In this scenario, I have taken the same above SharePoint list as Products and the same date field (Sales Date) is used to sort the gallery.
- Select the gallery control and set its Items property to the below code:
Items = Sort(
Products,
DateValue('Sales Date'),
Descending
)
Where,
DateValue = Power Apps DateValue is a type of function that helps to convert a date string to a date-time value. You can read this complete tutorial to know more details: How to use date time picker in PowerApps

- When we will save and preview the app, the gallery will look like the image below (in descending order).
In this way, We can work with Power Apps to sort the gallery by date.
Power Apps sort gallery by label
Now comes how to sort the Power Apps gallery by a label or what formula we can use to achieve this. Overlook the scenario below to know more details about this.
- In Power Apps, there is a Text input control and a Gallery control. A user will search the product over the search box and then the gallery will display all the search-related details in ascending order as shown below.
- Let’s say, When I searched for a product like Laptop, the gallery displayed all the laptop information in alphabetical order.

- To do so, we can use the code below on Gallery’s Items property as:
Items = SortByColumns(Filter(Products, StartsWith(Title, txtSearchProd.Text)), "Title", Ascending)
Where,
- Products = SharePoint List name
- Title = Specify the SharePoint field that the user will search in the search box
- txtSearchProd = Its the name of the text input control where a user will search the product
- Ascending = Specify the order that you would like to sort

This is how to work with Power Apps sort gallery by a label.
Read: Power Apps Search Gallery + 19 Examples
Power Apps gallery sort and filter
As we know, we can sort the gallery control based on any SharePoint field. Suppose you want to sort and filter the gallery at the same time. To work with it, we will use the Power Apps Filter and Sort function combination. Check out the scenarios below.
For all the below scenarios, I have used only one SharePoint list i.e. TSInfo Attachments. This list has many below columns with different data types:
- ID = By default, this is a Number column and it is a read-only field. A user cannot enter the ID value as it is an auto-generated field.
- Title = By default, this is a Single line of text data type.
- Attachment Types = This is a Choice column having some choice values like Microsoft Document, PPT, PDF, Excel, etc.
- Attachment Costs = This is a Currency field where a user can enter the Attachment cost.
- Attachment Created Date = It is a Date time column where a user can enter the created date of any attachment.

Now follow the below things.
Example – 1: (Filter by Attachment Types and Sort by Title field)
- In this scenario, we will filter the Power Apps gallery by the SharePoint Attachment types field and sort by the Title field.
- To achieve this, select the gallery control and set its Items property to the below formula:
Items = SortByColumns(
Filter(
[@'TSInfo Attachments'],
'Attachment Types'.Value = "PDF"
),
"Title",
Ascending
)
Where,
- TSInfo Attachments = Specify the SharePoint list name
- ‘Attachment Types’ = Specify the column that you want to filter. As it is a Choice column, that’s why we need to specify a .Value parameter
- “PDF” = Specify the value that you want to filter from the specific column
- “Title” = Specify the column name that you want to sort in the gallery
- Ascending = Specify the sort order either ascending or descending

When we save and preview the app, we can see the filter and sort result in the gallery control as shown in the above screenshot.
Example – 2: (Filter by Attachment Types and Sort by Attachment Created Date field)
- Next, we will filter the Power Apps gallery based on the Attachment types, and at the same time, the items will sort by the Attachment Created Date field.
- To work with this, we can use the below code on the gallery’s Items property:
Items = Sort(
Filter(
'TSInfo Attachments',
'Attachment Types'.Value = "Excel"
),
'Attachment Created Date',
Descending
)
Refer to the below screenshot.

Once we save and preview the app, we can see the gallery filtered with the choice value (PDF) and the date appeared in descending order.
Example – 3: (Filter by the first letter of Title and Sort by Attachment Created Date field)
Now in this scenario, we will see how to filter the first letter from the SharePoint Title field and sort the date field in Power Apps Gallery control.
- To workaround this, we can refer to the below code on the gallery’s Items property:
Items = SortByColumns(
Filter(
[@'TSInfo Attachments'],
StartsWith(
Title,
"P"
)
),
"AttachmentCreatedDate",
Descending
)
Where,
- StartsWith = Power Apps StartsWith is a function that helps to check whether the text string begins with another. To know more details about this function, check out this complete post: PowerApps StartsWith and EndsWith Functions
- Title = Specify the SharePoint column that you want to filter
- “P” = Mention the alphabet that starts within the title field

- Save and Preview the app. The gallery will appear with the filtered value in descending order as shown in the above screenshot.
This is how to work with a combination of sort and a filter functions in Power Apps Gallery.
Also, read: PowerApps toggle control + How to use with examples
Power Apps sort gallery by date and time
As I already discussed above that how to work with Power Apps sort gallery by date. Similarly, to work and learn more about Power Apps sort the gallery by date and time, you can directly refer to this link: Power Apps Sort by Date and time
Power Apps sort and search gallery
Suppose we want to sort and search the Power Apps gallery based on any specific SharePoint field. Follow the below scenarios to get some more ideas.
- For all the scenarios, I have taken one SharePoint list named Job Seekers Registration List. This list has the below columns with different data types:
- First Name = By default, it is a Title column with a Single line of text data type.
- SurName = Single line of text field
- Registration ID = This is a Number field that contains the ID value of a specific registrant.
- Matric Percentage, 12th Percentage, Graduation SGPA, Address for Correspondence = These are the single line of text fields

Refer to the below various examples.
Example – 1: (Power Apps sort and search gallery based on SharePoint Number field)
In this scenario, we will see how to sort and search the Power Apps Gallery based on the SharePoint Integer field i.e. Registration ID.
- In the below screen, you can see whenever the user does not search any ID in the search box, the gallery appears with all list records with sorting the registration IDs.
- When a user searches any specific ID in the search box (For example, 11), then the gallery filters and appears by searching related records with sorting.

- To achieve this, we will use the AddColumns function to create a new column that will hold the integer value.
- Select the Gallery control and apply the below code on its Items property as:
Items = SortByColumns(
Search(
AddColumns(
'Job Seekers Registration List',
"NewRegID",
Text('Registration ID')
),
txtSearchID.Text,
"NewRegID"
),
"RegistrationID"
)
Where,
- ‘Job Seekers Registration List’ = Specify the SharePoint List name
- “NewRegID” = Provide a unique name of the new field
- ‘Registration ID’ = Specify the SharePoint Number field. The Text function converts the integer value to a string.
- txtSearchID = This is the text input control name where a user will search the registration ID

Once we save and preview the app, the gallery will display all the user search-related records in ascending order.
Example – 2: (Power Apps sort and search gallery based on SharePoint Text field)
Next comes how we can sort and search the Power Apps Gallery based on the SharePoint Single line text field.
- In the below screenshot, there is a Text input control and a Gallery control. When a user searches the Surname of any job seeker, then the specific surname filtered details will appear in the gallery control as shown below.

- To do so, set the code below on the gallery’s Items property:
Items = SortByColumns(
Search(
'Job Seekers Registration List',
txtSearchSurname.Text,
"SurName"
),
"SurName"
)
Where,
txtSearchSurname = Text input control name where a user can search the Surname

- Save and Preview the app. When you will search for any Surname in the search box, then the gallery will filter and appear those search-related records.
Check out: PowerApps Now, Today, and IsToday function
Power Apps gallery sort by newest
Do you know what is the sort by newest in Power Apps Gallery? Getting the Gallery items from latest to oldest or vice versa is known as Power Apps Gallery sort by newest. Follow the below things to achieve it in Power Apps.
- It’s quite similar to the Power Apps sort gallery by date topic where we are sorting the gallery items based on the date field. Similarly, to sort the gallery based on the newest items, we can use the Date column (either default Created Date field or any Custom Date field that you have created) in the app.
- To workaround this, select the gallery control and set its Items property to the below code:
Items = Sort(
'TSInfo Attachments',
'Attachment Created Date',
Descending
)
Where,
- ‘TSInfo Attachments’ = SharePoint List name
- ‘Attachment Created Date’ = Date time field

- Now the items are sorted from new to old in the Power Apps Gallery control. Next, suppose, you want to include a Text search box without losing the Descending function within the gallery item. I would like the user to search items within a column named Title.
- To work around this, write the below code on the gallery’s Items property as:
Items = SortByColumns(
Filter(
'TSInfo Attachments',
txtSearchAttach.Text in Title
),
"AttachmentCreatedDate",
Descending
)
Where,
- txtSearchAttach = Text input control name where a user can search the Attachment
- Title = SharePoint single line of text field
Refer to the below screenshot.

- Save and Preview the app. When you will search any attachment in the search box, the gallery will filter and sort based on the created date as shown in the above figure.
Power Apps gallery sort distinct
This topic will show how to sort the distinct values in Power Apps Gallery control. We will use the Power Apps Sort and Distinct function combination to achieve this.
- For this thing, I have taken a SharePoint list named Products. This list has several different columns along with the Title column. I would like to filter all the distinct values from this title column and then sort them in the Power Apps Gallery control.
- There are two types of formulas that we can try out:
Formula – 1:
- Select the gallery control and set its Items property to the below code:
Items = Sort(
Distinct(
Products,
Title
),
Result
)
Where,
- Products = Mention the SharePoint List name
- Title = Specify the SharePoint column that you want to get the distinct values
- Result = All the distinct values will store in the Result column
Refer to the below screenshot.

- Next, select the label control from the gallery and set its Text property as:
Text = ThisItem.Result
- Once you will save and preview the app, the filtered sort records will appear in the gallery control as shown in the above screenshot.
Formula – 2:
There is another formula that you can try to work around this. Apply the below code on the gallery’s Items property as:
Items = Distinct(
Sort(
Filter(
Products,
true
).Title,
Title,
Ascending
),
Title
)
Where,
Title = Specify the SharePoint column that you want to get the distinct values and sort them alphabetically

- In the same way, select the label control from the gallery and set its Text property as:
Text = ThisItem.Result
- Save and preview the app, the filtered sort records will appear in the gallery control.
This is how to work with Power Apps gallery sort distinct.
Power Apps gallery sort get row number
Do you want to sort and display the row number in the Power Apps Gallery control? If so, then I already mentioned all these things in the other post that you can refer it easily.
Checkout: Power Apps gallery sort get row number
Power Apps gallery sort by multiple columns
Well, also we can sort the Power Apps Gallery control by using multiple SharePoint fields or columns. Refer to the below things to know its syntax and uses.
Syntax:
The below code represents the syntax or formula to work with the Power Apps gallery sorted by multiple columns.
SortByColumns( Table, ColumnName1 [, SortOrder1, ColumnName2, SortOrder2, ... ] )
Where,
- Table = Specify the Data source name or table name
- ColumnName1 , ColumnName2, and so on = Provide the Data source column names that you want to sort
- SortOrder1, SortOrder2, and so on = Specify the sort order as Ascending or Descending as per the need
To view how it works with the Power Apps gallery, follow the below scenario.
Example:
- I have a SharePoint list named Book Purchase Info. This list has four columns:
- Book Name = By default, this is a Single line of text Title column. I just renamed it to Book Name.
- Book Price = This is a Currency field having the book price value.
- Sales Date = It is a Date Time column.
- Book Seller = It is a Person field that contains the seller’s names.

- Next, I would like to sort the gallery by two different SharePoint fields i.e. Book Name (Title) and Book Price.
- To do so, select the gallery control and apply the below formula on its Items property as:
Items = SortByColumns(
'Book Purchase Info',
"Title",
Ascending,
"BookPrice",
Descending
)
Where,
Ascending, Descending = Mention the order that you want to sort the gallery items
Refer to the below image.

Also, to read more details about Power Apps sort by multiple fields, checkout this forum post:
Sort gallery with multiple fields
This is how to work with the Power Apps gallery sort by multiple columns.
Power Apps sort gallery by calculated field
Do you want to sort the SharePoint Calculated column in a Power Apps Gallery control? refer to the below simple scenario.
- There is a SharePoint list called COVID-19 Tracker. This list has five different data type fields. Such as:
- Country = This is a Choice column having some choice values like Australia, Brazil, Canada, Denmark, etc.
- Total Confirmed, Total Deaths, Total Recovered = These are the Number data type fields. And whenever you will create these columns, you must ensure to create the column names without giving any space.
- Deaths Percentage = This is a Calculated column that will calculate the Death percentage depending on the Total Recovered and Total Confirmed fields.

- Now, I would like to sort the gallery control based upon the Calculated field i.e. Deaths Percentage. To do so, we will use the Power Apps AddColumns function.
- Select the Power Apps gallery control and apply the below code on its Items property as:
Items = Sort(
AddColumns(
'COVID-19 Tracker',
"SortField",
TotalRecovered / TotalConfirmed * 100
),
SortField,
Descending
)
Where,
- “SortField” = Provide a new unique name where all the percentage values will store.
- Descending = As I want to view the largest data first, that’s why I specified the order as descending.

- Next, select the label from the gallery and set its Text property as:
Text = "Death Percentage: " & ThisItem.SortField
- Once you will save and preview the app, the gallery will appear with sort filtered records based on the calculated field.
This is how to work with Power Apps sort gallery by calculated field.
Also, you may like some below Power Apps Tutorials:
- What is Microsoft Dataverse
- Dataverse Create Table [With Examples]
- Create Collection from SharePoint List in PowerApps
- Power BI integration with PowerApps Portals
- Power Apps Azure AD Group
- Power Apps RSS Feed
- PowerApps Weather
- PowerApps Twitter Connector
- Power Apps Calculate + 13 Examples
- Build a Calculator in Power Apps
- Power Apps Rating Control – How to use
- Power Apps Slider Control
- Power Apps Data Table – Complete tutorial
- Power Apps Export Import Control – How to use
- Power Apps Sort
In this Power Apps tutorial, we discussed what is the difference between the Sort function and the Sort gallery in Power Apps. Also, by taking some simple scenarios, we covered these topics below:
- Power Apps sort gallery Or Power Apps gallery sort ascending descending
- Power Apps sort gallery items
- Power Apps sort gallery by choice column
- Power Apps sort gallery by date
- Power Apps sort gallery by label
- Power Apps sort gallery based on dropdown
- Power Apps gallery sort and filter
- Power Apps sort gallery by date and time
- Power Apps sort and search gallery
- Power Apps gallery sort by newest
- Power Apps gallery sort distinct
- Power Apps gallery sort get row number
- Power Apps gallery sort by multiple columns
- Power Apps sort gallery by calculated field
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com
Great post!
I’d recommend a “conflict” in the two column sort example, to show how it works…