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 Name | Data Type |
| Destinaton | It is a default single line of text |
| Expense Name | A single line of text |
| Category | Choice |
| Total Cost | Number |
| Start Date | Date and time |
| End Date | Date and time |

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

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

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.

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

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:

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
)

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
)

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

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

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.

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

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

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.

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

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:

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

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
How to sort a Power Apps gallery by ID with a search box or a custom ID column
To keep a search box and still show the newest items first, wrap your Filter inside Sort and sort on ID in descending order. If your list uses its own number column, such as Employee ID, sort on that column instead of the built-in ID.
Search the gallery and keep the newest ID on top
Add a Text input named txtSearchFile above the gallery, then set the gallery’s Items property like this:
Sort(
Filter(
'TSInfo Attachments',
StartsWith(Title, txtSearchFile.Text)
),
ID,
SortOrder.Descending
)
When the box is empty, StartsWith matches every row, so you see the full list. As you type, the gallery narrows to titles that begin with your text, and the highest ID always stays at the top.

StartsWith on a text column and Sort on a number column both delegate to SharePoint, so this works on large lists. Just don’t filter the ID column with < or >, because SharePoint only delegates the equals operator on ID.
Sort by a custom number column
Many lists track their own key, like an Employee ID number column. Sort works the same way. Just point it at that column:
Sort(
'Employee Onboarding',
'Employee ID',
SortOrder.Descending
)

Swap SortOrder.Descending for SortOrder.Ascending if you want the lowest number first.
How to sort a Power Apps gallery by month or day
To show one month or one day in date order, filter the gallery to a date range with >= and <, then sort on the date column. Build the range with Date() and Today() instead of wrapping your column in Month().
Why? Month() inside Filter doesn’t delegate to SharePoint, so a large list quietly returns incomplete results. A plain date comparison delegates fine.
Let users pick a month from a dropdown
First, create a small month table in the App’s OnStart property, then run OnStart once so the collection exists while you build:
ClearCollect(
collMonths,
Table(
{ID: 1, Name: "Jan"}, {ID: 2, Name: "Feb"}, {ID: 3, Name: "Mar"},
{ID: 4, Name: "Apr"}, {ID: 5, Name: "May"}, {ID: 6, Name: "Jun"},
{ID: 7, Name: "Jul"}, {ID: 8, Name: "Aug"}, {ID: 9, Name: "Sep"},
{ID: 10, Name: "Oct"}, {ID: 11, Name: "Nov"}, {ID: 12, Name: "Dec"}
)
)
Add a Dropdown named drpMonth, set its Items to collMonths, and use this for the gallery’s Items:
With(
{
StartDate: Date(Year(Today()), drpMonth.Selected.ID, 1),
EndDate: Date(Year(Today()), drpMonth.Selected.ID + 1, 1)
},
Sort(
Filter(
'Company Attachments',
'Attachment Created Date' >= StartDate,
'Attachment Created Date' < EndDate
),
'Attachment Created Date',
SortOrder.Ascending
)
)

Picking Dec works too. Date() rolls month 13 over to January of the next year, so the December 2026 range ends on January 1, 2027.
Current, next, or previous month
Use the same pattern and shift the month number. For the current month, StartDate is Date(Year(Today()), Month(Today()), 1) and EndDate is Date(Year(Today()), Month(Today()) + 1, 1).
- Next month: add 1 to both month numbers (+1 and +2).
- Previous month: use -1 for StartDate and Month(Today()) for EndDate, and sort descending so the latest items show first.
- Last or next N months: widen the gap, for example Month(Today()) – 2 for StartDate and Month(Today()) + 1 for EndDate.
Today, tomorrow, or the last N days
Day ranges work the same way, using Today() plus or minus whole days. Here’s today’s purchases, sorted A to Z by title:
Sort(
Filter(
'Product Details',
'Purchase Date' >= Today(),
'Purchase Date' < Today() + 1
),
Title,
SortOrder.Ascending
)

- Tomorrow: >= Today() + 1 and < Today() + 2.
- Yesterday: >= Today() – 1 and < Today().
- Last 3 days: >= DateAdd(Today(), -3, TimeUnit.Days), with no upper limit needed.
Using < on the end date, rather than <=, also catches items saved late in the day when your column includes a time.
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

This is how we can work with the Power Apps sort and filter.
Some more Power Apps articles you may also like:
- Power Apps Sort Gallery By Day
- Power Apps Sort Distinct Filter
- How to Use Power Apps Find Function
- How to Sort Data Table in Power Apps
- How to Sort Dropdown Choices Alphabetically in Power Apps
- Save Power Apps Current User and Manager Name in SharePoint Person Column
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.

Hey! I’m Bijay Kumar, founder of SPGuides.com and a Microsoft Business Applications MVP (Power Automate, Power Apps). I launched this site in 2020 because I truly enjoy working with SharePoint, Power Platform, and SharePoint Framework (SPFx), and wanted to share that passion through step-by-step tutorials, guides, and training videos. My mission is to help you learn these technologies so you can utilize SharePoint, enhance productivity, and potentially build business solutions along the way.
Great post!
I’d recommend a “conflict” in the two column sort example, to show how it works…
Hi Bijay,
Is there a way to sort by more than one choice column?