# Power Apps Sort Function [With 19 useful examples]

In this Power Apps tutorial, We will discuss what the Power Apps Sort function is, what is Power Apps SortByColumns function, and their syntaxes.

Also, by taking various scenarios, we will cover these below topics:

• Power Apps Sort Gallery
• Power Apps sort distinct filter
• Power Apps sort dropdown choices
• Power Apps sort by choice column
• Power Apps sort ascending descending
• Power Apps sortbycolumns choice column
• Power Apps sort and filter datatable
• Power Apps sort and filter on multiple columns
• Power Apps sort by specific value
• Power Apps sort by calculated field
• Power Apps sort by id
• Power Apps Sort Collection or Power Apps sort collection alphabetically
• Power Apps Sort Collections on Multiple columns
• Power Apps Sort Combobox
• Power Apps sort list box
• Power Apps Sort by Month
• Power Apps Sort Priority
• Power Apps Sort by Person Column

## Power Apps Sort Function

Power Apps Sort function helps to sort the table depending on the formula provided by the user. The formula output must be an integer, a Boolean, or a string value. The output cannot be in a table or record.

Syntax:

Below represents the syntax of the Power Apps Sort Function:

``Sort( Table, Formula [, SortOrder ] )``

Where,

• Table = This is required. Specify the table name that you want to sort.
• Formula = This is also required where the formula helps to execute each and every record of the table. And the outputs are used to sort the table.
• SortOrder = This is optional. You need to provide an order format like SortOrder.Descending to sort the table in descending order where the SortOrder.Ascending helps to sort the table in ascending order. SortOrder.Ascending is the default value.

## Power Apps sort by columns

Power Apps SortByColumns is a type of function that helps to sort the table based on multiple fields or columns.

Syntaxes:

Below represents the syntaxes of the Power Apps SortByColumns Function:

Syntax – 1:

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

Where,

• Table = This is required. Specify the table name that you want to sort.
• ColumnName(s) = This is also required. Provide the column names that you want to sort, as strings.
• SortOrder(s) = This is optional. You need to specify the order as SortOrder.Ascending or SortOrder.Descending. And, SortOrder.Ascending is the default value. If multiple ColumnNames are supplied, all but the last column must include a SortOrder.

Syntax – 2:

``SortByColumns( Table, ColumnName, SortOrderTable )``

Where,

• Table = This is required. Specify the table name that you want to sort.
• ColumnName = This is also required. Provide the column name that you want to sort, as strings.
• SortOrderTable = This is also a required parameter. Specify the single-column table of values to sort by.

## Power Apps Sort Gallery

Do you want to read all the details about the Power Apps Sort Gallery? If so, then refer to this complete Power Apps tutorial to get more ideas: Power Apps Sort Gallery [With 15 Useful Examples]

## Power Apps sort distinct filter

Suppose you want to sort and filter the distinct values at a time in Power Apps. Then, in this case, we will use three Power Apps functions in the same formula. Such as Sort, Distinct, and Filter. We can combine all these three functions and get the result either in a gallery control or a Dropdown control in Power Apps.

Refer to the below scenarios.

Example – 1:

• The below screenshot represents a SharePoint list named Scheduled Events. This list has various columns with different data types. Such as:
1. Title = By default, this is a single line of text field that defines the event names.
2. Department = This is a Choice column having some choice values like IT, HR, FINANCE, MARKETING, etc.
3. Location = This is also a Choice column having some choice values like Pentagon, Decagon, Octagon, Nonagon, etc.
4. Event Manager = It is a Person field that holds the event manager names.
5. Start Date, End Date = These are the Date time field that contains all the event start and end dates.
• Next, in the app, there are two Dropdown controls where one of the dropdowns is used to select the department and another one is to display the location based on the department selection.
• Now what I would like to do is, the user will select the Department (from the first dropdown), and then the Location (second dropdown) will filter accordingly based on the department dropdown with distinct and sort values.
• For example, when I selected the department of MARKETING, the location dropdown was filtered with distinct values and sorted accordingly (in Ascending order).
• To achieve this, select the Department dropdown control and apply the below code on its Items property as:
``Items = Choices('Scheduled Events'.Department).Value``

Department = SharePoint Choice field

• Once we preview the app, we can see all the department choice values inside the dropdown menu.
• Next, select the Location dropdown and set its Items property to the code below:
``````Items = Sort(
Distinct(
Filter(
'Scheduled Events',
Department.Value = ddSelectDepartment.Selected.Value
),
Location.Value
),
Result,
Ascending
)``````

Where,

1. Department.Value = Department is a SharePoint Choice field, that’s why we need to specify the .Value parameter.
2. ddSelectDepartment = This is the first dropdown control name where a user can select the Department value.
3. Location.Value = Location is a SharePoint Choice field, that’s why we need to specify the .Value parameter.
4. Result = This is the second required argument in the formula.
5. Ascending = Specify the order that you want to display in the second dropdown control.
• Save and Preview the app. You can see the result in the location dropdown once you select the department dropdown menu.

Example – 2:

There is a SharePoint list named Job Seekers Registration List. This list has some different fields like below:

1. First Name = By default, this is a Title field with a single line of text data type. I just renamed it to First Name.
2. SurName = This is also a single line of text field
3. Registration ID = Number data type field
4. Matric Percentage, 12th Percentage, Graduation SGPA, Address = All these are Single line of text fields

Now, in this scenario, I would like to sort the Title field and that should be a unique value in Power Apps.

• To do so, insert a Gallery control and apply the below formula on its Items property as:
``````Items = Sort(
Distinct(
'Job Seekers Registration List',
Title
),
Result
)``````

Refer to the screenshot below.

• Finally, select the label that is present inside the gallery and set the below code on its Text property as:
``Text = ThisItem.Result``
• When you will save and preview the app, the gallery will appear with the filtered distinct result in ascending order.

This is how to work with the sort distinct filter in Power Apps.

## Power Apps sort dropdown choices

In this topic, we will see how to sort the dropdown choice values in Power Apps. Follow the below scenarios.

• I have a SharePoint list called TSInfo Attachments that contain these below fields:
1. ID = By default, this is a number and read-only field in the list.
2. Title = By default, this is a single line of the text field.
3. Attachment Types = It is a Choice field having some choice values like PPT, PDF, Excel, Microsoft Document, etc.
4. Attachment Costs = This is a Currency field
5. Attachment Created Date = Date time column

For all the below scenarios, I have used the above SharePoint list.

Scenario – 1: (Power Apps Sort Dropdown with Single line of text field)

• Now, I would like to sort the SharePoint Title field values in a Power Apps Dropdown control. That means, all the attachment names should appear in descending order in the dropdown menu as shown below.
• To work around this, select the Dropdown menu and set its Items property as:
``````Items = Sort(
'TSInfo Attachments',
Title,
Descending
).Title``````

Where,

Descending = The order, that I want to display the values in the dropdown menu

• When we save and preview the app, the gallery will display the sort results.

Scenario – 2: (Power Apps Sort Dropdown with Choice field)

• Next, in this scenario, we will see how to sort the Dropdown menu with a SharePoint Choice column. In the below screenshot, you can see all the Attachment types are appearing in ascending order in the dropdown control.

To achieve this, we can use three different types of formulas. Such as:

Formula – 1:

• Select the Dropdown control and set its Items property to the below code:
``````Items = Sort(
Choices([@'TSInfo Attachments'].'Attachment Types'),
Value
)``````

Where,

1. TSInfo Attachments‘ = SharePoint List name
2. Attachment Types‘ = SharePoint Choice column name

Formula – 2:

• Below represents the second code that we can use to sort the choice values in the Power Apps dropdown control i.e.
``````Items = Sort(
Choices([@'TSInfo Attachments'].'Attachment Types'),
ThisRecord.Value
)``````

Formula – 3:

• Also, there is another formula that we can apply by using the Power Apps SortByColumns function i.e.
``````Items = SortByColumns(
Choices([@'TSInfo Attachments'].'Attachment Types'),
"Value"
)``````

All the above codes are tested and it is working correctly in the app.

This is how to work with Power Apps to sort dropdown choices.

## Power Apps sort by choice column

As in the above scenarios, we already discussed how we can sort the Choice column in Power Apps Dropdown control. Moreover, the below represents another scenario that we can refer to.

• In the screenshot below, there is a SharePoint Choice field (Product Capacity) having some number choice values like 4, 8, 32, 128, and 500.
• Now in the app, I want to display those number choice field values in ascending order in a dropdown control as shown below.
• To achieve this, select the Items property of the Dropdown control and apply the code below:
``````Items = Sort(
Choices([@Products].'Product Capacity'),
"Value"
)``````

Where,

1. Products = Specify the SharePoint List name
2. ‘Product Capacity’ = Provide the SharePoint Choice field name

Refer to the below screenshot.

• Once we will save and preview the app, the dropdown menu will appear with all the choice values in ascending order.

This is how to work with Power Apps sort by choice column.

## Power Apps sort ascending descending

To work with Power Apps sort Ascending or Descending, you can check out this Power Apps forum post to get some ideas: Power Apps sort ascending descending

## Power Apps SortbyColumns choice column

In this topic, we will see how to work with the Power Apps SortbyColumns Choice column. Follow the below simple scenario.

• There is a SharePoint list called Employee Onboarding. This list has some columns like ID, Title (Employee Name), Employee Last Name, Employee ID, Department, and Location.
• Now I would like to search and sort the gallery based on these four columns i.e. Department, Location, Employee First Name(Title), and Employee Last Name.
• A user can search any field value by using one single text input box and the filtered result will display in the gallery control as shown below.
• To work with this, we will use the OR operator in the formula. Set the below code on the gallery’s Items property as:
``````Items = Sort(
Filter(
'Employee Onboarding',
txtSearchField.Text in Department.Value || txtSearchField.Text in Location.Value || txtSearchField.Text in Title || txtSearchField.Text in EmployeeLastName
),
Department.Value
)``````

Where,

1. txtSearchField = Text input control name where a user can search multiple columns like Department, Location, Title, and Employee Last Name
2. Department, Location = As both are Choice fields, that’s why we need to apply a .Value parameter
3. Title, EmployeeLastName = These are the single line of text fields

This is how to work with Power Apps SortbyColumns choice column.

Also, read: PowerApps Find Function With Examples

## Power Apps sort and filter Datatable

Do you want to sort and filter the Power Apps Data table? Refer to the below different scenarios.

• There is a SharePoint list named Job Seekers Registration List. This list has various fields with different data types. Among them, there are two fields named Apply Date (Date time data type) and Status (Choice) fields that we are going to use in the app.
• Here, I want to filter and sort the data table records based on the list Status field where the Apply date is less than or equal to today.
• To work around this, Select the Data table control and set its Items property to the below code:
``````Items = SortByColumns(
Filter(
'Job Seekers Registration List',
Status.Value = "Approved"
),
"ApplyDate",
Descending
)``````

Where,

1. Status.Value = This is a Choice field having some choice values like Submitted, Pending, Approved, Rejected, etc. As it is a choice column, we need to specify the .Value parameter.
2. “Approved” = Specify the Choice value that you want to filter in the data table
3. “ApplyDate” = Date time field
4. Descending = Specify the order that you want to display in the data table control
• Now suppose you want to count the total number of approved records that are present inside the data table control. In this case, insert a Label control and set its Text property to the below code:
``````Text = "Total Status Count: " & CountIf(
'Job Seekers Registration List',
Status.Value = "Approved" && DateDiff(
Today(),
'Apply Date'
) <= 0
)``````

Where,

1. Total Status Count: ” = This is a text that will appear in the label control
2. CountIf = This is a Power Apps function that helps to count the total number of items in the data table control. To know more details about this function, read: PowerApps CountIf Function with Examples
3. DateDiff = Power Apps DateDiff function helps to return the difference between two date or time values. Also, you can read more details by referring to this link: How to use date time picker in PowerApps
• When we save and preview the app, the result will appear as 3 (because there is a total of three approved items in the data table) in the label control as shown in the above screenshot.

To know more details about Power Apps sort and filter Datatable, check out the below tutorials:

## Power Apps sort and filter on multiple columns

Would you like to sort and filter on multiple columns in Power Apps? Yes, it is possible by using the Power Apps OR operator. Follow the below instructions to work with this.

• I have a SharePoint list named Products. This list has many below fields with different data types. Such as:
1. ID = By default, this is a Number data type and read-only field
2. Title = By default, this is a Single line of the text field
3. Vendor = This is a Choice column having choice values like APPLE, SAMSUNG, DELL, HP, etc.
4. Customer Name = This is a single line of the text field
5. Quantity = Number Data type column
6. Sales Date = Date time field
7. Status = It is a Choice field having choices like Submitted, Approved, Rejected, Pending, etc.
• In the app, there is a Text input control and a Gallery control. By using the text input control, a user can search the product title, vendor, and as well product status values.
• Then the gallery will filter based on the user-searched value and the filtered records will appear in ascending order as shown below.
• To achieve this, select the gallery and apply the below code on its Items property as:
``````Items = SortByColumns(
Filter(
[@Products],
StartsWith(
Title,
txtSearchBox.Text
) || StartsWith(
Vendor.Value,
txtSearchBox.Text
) || StartsWith(
Status.Value,
txtSearchBox.Text
)
),
"Title",
Ascending
)``````

Where,

1. Products = Specify the SharePoint list name
2. Title = Single line of the text field
3. txtSearchBox = Text input control name where a user can search the Title, Vendor, and Status values
4. Vendor, Status = As these both are Choice fields, that’s why we need to specify the .Value parameter
5. Ascending = Specify the order that you want to view in the gallery items
• Once you apply the formula, you may get the delegation issue in the filter part of the formula that might not work with large data sets. To overcome it, instead of using the SharePoint list directly, we can create a Power Apps Collection and use that collection within the formula.

Refer to the below screenshot.

• Finally, Save and Preview the app. Search either any Product title, vendor or status value inside the search box, then the gallery will display the filtered records in ascending order.

This is how to work with sort and filter on multiple columns in Power Apps.

Also, check out this post: PowerApps toggle control + How to use with examples

## Power Apps sort by specific value

• Power Apps sort by a specific value, what does it mean? Do you know, that we can sort our records based on the text field (by predefined order) rather than alphabetically? And, that can be possible by using the Power Apps SortByColumns function.
• When we are using the SortOrder.Ascending or the SortOrder.Descending as the sort order within your SortByColumns function, all the records would be sorted alphabetically. In the same way only, we also can take a try to customize our soft order within our SortByColumns function.
• We can sort our records based on the name of a day of the week by supplying [ “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday” ] as the sort order. All records which have Monday” will come first, followed by Tuesday, and so on.
• Not only the week, but also we can try any of the predefined values based on months like January, February, March, and so on. Check out the below scenario to achieve it.
• There is a SharePoint list named Book Purchase Info. This list has various columns with different data types. Among all, it has a single line of text field called Purchase Day. This field contains all the week names like Monday, Friday, Saturday, Thursday, etc. as shown below.
• Now, in the app, whenever I am applying the common sort function formula to the gallery, the gallery is appearing in alphabetically ascending order like Friday, Monday, Saturday, Sunday, etc.
• But what I want to do is, I need to display the gallery control in a predefined order (like Monday, Tuesday, Wednesday, etc.) instead of alphabetical order as below.
• This is the common formula that I have used first in the gallery’s Items property and the result came out in alphabetical order.
``````Items = SortByColumns(
'Book Purchase Info',
"PurchaseDay",
Ascending
)``````
• Now, instead of the above formula, we will use this code below on the gallery’s Items property as:
``````Items = SortByColumns(
'Book Purchase Info',
"PurchaseDay",
[
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
]
)``````

Refer to the figure below.

• Once we save and preview the app, we can view the result in the gallery control.

This is what does the mean of Power Apps sort by specific value.

## Power Apps sort by Calculated field

Is it possible to sort the items by using the SharePoint Calculated field in Power Apps? Yes, we can sort the records by using the Calculated field, and it’s very easy to use in the formula. Check out this below scenario.

• There is a SharePoint list named Global COVID-19 Tracker that contains the many below columns:
1. Country = This is a Choice field having some choice values like Australia, Brazil, Canada, etc.
2. Total Confirmed = This is a Number field that contains the total number of confirmed cases.
3. Total Recovered = This is a Number field that contains the total number of recovered cases.
4. Total UnRecovered = This is a Calculated field that calculates the total number of unrecovered cases based upon the confirmed and recovered fields.
• The below screenshot represents the Calculated field (Total UnRecovered) where it calculates the value based on two other fields i.e.
``Formula = [Total Confirmed]-[Total Recovered]``
• Now what I want to do is, I would like to sort all these calculated values in descending order. And the records will display in a Data table control in the app as shown below.
``````Items = SortByColumns(
'Global COVID-19 Tracker',
"SortField",
'Total Confirmed' - 'Total Recovered'
),
"SortField",
Descending
)``````

Where,

sortField” = Provide a new unique name where all the calculated values will store

• Finally, add that new field (SortField) into the data table control by using the Edit fields option. Once we add it, the data table will appear with all the calculated records in descending order.

This is how to work with Power Apps sort by Calculated field.

## Power Apps sort by id

In Power Apps, do you want to sort the record by using the SharePoint ID field? It’s so simple to achieve this.

• In the below screenshot, you can see, that there is a Text input control and a Gallery control in the app. A user will search the file name by using the text box. When a user does not search anything or when the search box is empty, then the gallery will appear with all the SharePoint list records.
• When the user searches any file name in the search box, then the gallery filters based on the user search-related records in descending order (based on ID values) as like below.
• 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",
Descending
)``````

Where,

1. TSInfo Attachments‘ = Specify the SharePoint list name
2. StartsWith = This is a type of Power Apps function that helps to 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
• Save and preview the app. Once you search the file in the search box, the gallery will filter and display the filtered records based on the ID field (in descending order).

To read more examples about the sort by id in Power Apps, refer to this tutorial: Power Apps sort gallery by id

This is the mean of Power Apps sort by id.

## Power Apps Sort Collection or Power Apps sort collection alphabetically

Here, Power Apps Sort Collection and Power Apps sort collection alphabetically, both are the same. Let’s understand how it works in the app.

• The below screenshot (first image) represents a Power Apps Collection named colProducts. In that collection, there are three columns as Manufacturer, Name, and Price.
• Now, I would like to sort the Price field in ascending order and that should look like in the second screenshot (colsortProducts). Refer to the below processes to work with it.
• At first, in the app, Insert two Button controls where one button is used to create the collection and another one is used to sort the Price values from that specific collection.
• Select the first button control (Click to Create Product Collection) and apply the code below on its OnSelect property to create a collection:
``````OnSelect = ClearCollect(
colProducts,
{
Name: "Laptop",
Manufacturer: "Brazil",
Price: 350000
},
{
Name: "Mobile",
Manufacturer: "Denmark",
Price: 450000
},
{
Name: "Tablet",
Manufacturer: "America",
Price: 80000
},
{
Name: "Desktop",
Manufacturer: "France",
Price: 178000
}
);``````

Where,

1. colProducts = Specify the collection name
2. Name, Manufacturer, Price = These are the headers of the collection
3. Laptop“, “Brazil“, 350000 = These are the collection records
• Next, to sort the Price values, we will create another collection on the second button’s (Click to Sort Product Collection) OnSelect property as:
``````OnSelect = ClearCollect(
colsortProducts,
Sort(
colProducts,
Price,
Ascending
)
);``````

Where,

1. colsortProducts = Specify the new collection name where the price value will sort and store
2. colProducts = Provide the first collection name
3. Price = Provide the collection column name that you want to sort
4. Ascending = Specify the order that you want to sort

Refer to the below screenshot.

### Power Apps Sort Collections on Multiple columns

• Suppose you want to sort the Power Apps collections based on the multiple columns. For example, I want to sort the collection based on the Manufacturer field and as well as the Price field.
• To workaround with this, select the Button and apply the below formula on its OnSelect property as:
``````OnSelect = ClearCollect(
colsortProducts,
SortByColumns(
colProducts,
"Manufacturer",
Ascending,
"Price",
Descending
)
);``````
• Finally, save and preview the app. Click on the first button, and then the second button. Now to view the sort results, we can go to the Collections section (View -> Collections) and click on the second collection i.e. colsortProducts.

This is how to work with Sort Collection or sort collection alphabetically in Power Apps.

## Power Apps Sort Combobox

Do you want to sort the Combobox in Power Apps? If so, then refer to the below simple scenarios.

Example – 1:

• There is a SharePoint list named TSInfo Attachments. This list has various columns with different data types. Among them, there is an ID field (Number), Title field (Single line of text), and an Attachment Created Date field (Date time).
• Also, this list has some records like the below screenshot.
• In the app, there is a Combobox control. Next what I want to do is, I would like to sort the combo box by the Attachment created date in the app.
• In the below image, we can see whenever a user does not search for anything inside the combo box, the IDs are appearing in a descending order based on the Attachment Created Date field.
• Similarly, when a user finds any attachment (let’s say PowerApps) inside the Combobox control, then the IDs are appearing in the same descending order based on the Attachment Created date field.
• To achieve this, we will use the Power Apps AddColumns function. Select the Combobox control and set its Items property as:
``````Items = Sort(
'TSInfo Attachments',
"NewID",
Text(ID)
),
'Attachment Created Date',
Descending
)``````

Where,

1. TSInfo Attachments‘ = Specify the SharePoint List name
2. NewID” = Provide an unique column name with inverted comma (” “)
3. Text(ID) = Text function helps to convert the integer ID value to text value
4. Attachment Created Date‘ = This is a Date time field based on the ID values that will sort
5. Descending = Specify the order that you want to sort

Save, preview, and perform the app as per your need.

Example – 2:

• In the below scenario, there is a Combobox control that contains some alphabets on its Items property: (the Combobox should be a multiple select Combobox control)
``Items = ["D", "A", "F", "L", "S", "C", "U"]``
• Now, whenever I will select multiple numbers of alphabets from the Combo box control, then all the selected alphabets will sort in a Gallery control once I click on the Button control.
• For example, suppose I selected some alphabets like S, D, F, and U. When I click on the SORT button, then all the alphabets will sort in ascending order and display in the gallery control as shown below. To do so, follow the below processes.
``````OnSelect = ClearCollect(
myCollection,
Sort(
cbItems.SelectedItems,
Value
)
)``````

Where,

1. myCollection = Provide a new collection name
2. cbItems = Combo box control name
• Next, select the gallery control and set its Items property to the collection name:
``Items = myCollection``

Save, preview, and perform the app as per your need.

Example – 3:

This is the third scenario where I want to sort the SharePoint Choice field values in a Power Apps Combobox control.

• For this scenario also, I have used the same SharePoint list (TSInfo Attachments) from the first scenario. In this example, I have used the Choice field named Attachment Types which contains some choice values like Microsoft Document, PDF, PPT, Notepad, etc.
• Now in the app, I would like to display these choice field values in a Combobox control and the values should be in alphabetical order as shown in the screenshot below.
• To work around this, we can use both the Power Apps functions as Sort and SortByColumns. There are two formulas that we can use in the Combobox’s Items property:
``````Items = Sort(
Choices([@'TSInfo Attachments'].'Attachment Types'),
Value
)``````

Where,

1. TSInfo Attachments‘ = Specify the SharePoint List name
2. Attachment Types‘ = Provide the SharePoint Choice field that you want to sort in the Combobox

Or,

``````Items = SortByColumns(
Choices([@'TSInfo Attachments'].'Attachment Types'),
"Value"
)``````
• In the above code, I have used an inverted comma (” “) for the Sortbycolumns function. Refer to the below screenshot.
• Once we save and preview the app, the combo box will appear with the choice values in ascending or alphabetical order.

This is how to work with Power Apps Sort Combobox.

## Power Apps sort list box

Do you want to sort the list box items in Power Apps? Check out this Power Apps tutorial to know more details about it: Power Apps sort list box.

## Power Apps Sort by Month

Do you want to filter and sort the Power Apps gallery based on the Month? If so, then check out the below scenario to achieve it.

In Power Apps, there is a Dropdown menu that filters a gallery by MONTH and it sorts the gallery based upon the Created Date.

• There is a SharePoint List named TSInfo Attachments. It has a Date time column called Attachment Created Date. Also, this list has some records as shown below.
• Now in the app, When I will select any month from the Dropdown menu, then the gallery will filter and display all the records based on the specific month. Also, the Attachment created date field will sort in ascending order.
• For example, I selected the month as “MAY” from the dropdown, and then the gallery filtered based on May month and displayed all the records that are present under May month. Also, you can see the Attachment created date sorted in ascending order as in the below screenshot.
• To do so, we need to create a collection where all the Months will store on it. Apply the below code on the screen’s OnVisible property as:
``````OnVisible = ClearCollect(
collMonths,
{
ID: 1,
Name: "JAN"
}
);
Collect(
collMonths,
{
ID: 2,
Name: "FEB"
}
);
Collect(
collMonths,
{
ID: 3,
Name: "MAR"
}
);
Collect(
collMonths,
{
ID: 4,
Name: "APR"
}
);
Collect(
collMonths,
{
ID: 5,
Name: "MAY"
}
);
Collect(
collMonths,
{
ID: 6,
Name: "JUN"
}
);
Collect(
collMonths,
{
ID: 7,
Name: "JUL"
}
);``````

Where,

1. collMonths = Specify the Power Apps Collection name
2. ID, Name = These are the headers of that specific collection
3. 1“, “2“, and so on = These are the records that will store under the ID column
4. JAN“, “FEB“, and so on = These are the records that will store under the Name column

As I need up to the July month, that’s why I specified the code till July. You can add other months as per your requirement basis.

• Next, select the Dropdown control and set its Items property to the created collection as:
``Items = collMonths``

The dropdown menu will appear till July month. Refer to the below image.

• Now, select the gallery control and set its Items property as:
``````Items = Sort(
Filter(
'TSInfo Attachments',
Month('Attachment Created Date') = ddSelectMonth.Selected.ID
),
'Attachment Created Date',
Ascending
)``````

Where,

1. Attachment Created Date‘ = Date time field
2. ddSelectMonth = Dropdown control name
• Save, Publish, and Close the app. Reopen the app again and select any particular month from the dropdown menu. The filtered result will appear in the gallery control based on the month including the sort created date.

This is how we can work with Power Apps Sort by Month.

Also, read: Power Apps PDF Viewer â€“ Complete tutorial

## Power Apps Sort Priority

In this topic, we will see how to sort the gallery by priority order highest to lowest or lowest to highest.

• First of all, what does the mean of sort priority in Power Apps? To give the answer to this question, Suppose, there are three types of priorities Very High, Medium, and Normal.
• Now, I would like to show all the highest priority first, then medium and finally normal based upon the user selected. To know more details, follow the below scenario.

Scenario:

• There is a SharePoint list named IT Help Desk. This list has some fields with various data types. Such as:
1. Title = By default, this is a single line of text data type.
2. Request ID = This is a Number field data type.
3. Request Date = Date time field
4. SR Type = This is a Choice field that has some values like Change, Incident, Problem, Request, etc.
5. Category = This is also a Choice field that contains some choices like Servers, User Workstation, Basic Software, Data Center, etc.
6. Request User = It is a Person field data type
7. Priority = Choice field that contains some choice values like Very High, Medium, Normal
• In the app, there is a Dropdown control and a Gallery control that looks like the image below. The dropdown control holds all the request users (people picker field) from the SharePoint list.
• When a user will select any user name from the dropdown menu, then the gallery will filter and display all the records based upon the Priority field values.
• That means, if I selected the requester as “Bijay Kumar Sahoo” from the dropdown menu, then the gallery filters and displays the Highest priority record first, and then so on like the below image.
• To achieve this, first, apply the below code on Dropdown’s Items property as:
``````Items = Distinct(
'IT Help Desk',
'Request User'.DisplayName
)``````

Where,

1. ‘IT Help Desk’ = Specify the SharePoint list name
2. ‘Request User’.DisplayName = As this is a Person field, that’s why we need to mention the parameter value as .DisplayName
• Next, select the gallery control and set the below formula on its Items property as:
``````Items = Sort(
Filter(
'IT Help Desk',
'Request User'.Email = ddSelectRequester.Selected.Result || 'Request User'.DisplayName = ddSelectRequester.Selected.Result
),
Priority.Value,
Descending
)``````

Where,

1. ddSelectRequester = Dropdown control name
2. Priority.Value = Provide the SharePoint Choice field that you want to sort in the gallery
3. Descending = Specify the order that you want to view in the gallery (either higher priority to lower priority or vice versa)
• Save and Preview the app. Select any of the requesters of whom you want to see the ticket and then the result you can see in the gallery control on an order basis.

This is how to work with sort priority in Power Apps.

## Power Apps Sort by Person Column

Do you want to sort the SharePoint Person field in the Power Apps Gallery control? If so, then check out the below scenarios and formulas to achieve this.

Example – 1:

• The below screenshot represents a SharePoint list named Scheduled Events. This list has various fields with various data types. Among all, there is a Person or People picker field called Event Manager.
• Now, I would like to sort the Person field (Event Manager) in a Power Apps gallery control and that will look alike the below screenshot.
• To do so, select the Gallery control and apply the below code on its Items property as:
``````Items = SortByColumns(
'Scheduled Events',
"PersonsName",
'Event Manager'.DisplayName
),
"PersonsName"
)``````

Where,

1. “PersonsName” = Provide a unique name where the SharePoint person values will store
2. ‘Event Manager’ = Specify the SharePoint Person field that you want to sort in the gallery
• Finally, you need to set the label text value as well within the gallery control. Select the label inside the gallery and set its Text property as:
``Text = "Manager: " & ThisItem.PersonsName``

Where,

1. “Manager: “ = This is the string that will display in the label control
2. PersonsName = Specify the new column that you have added just before (where all the person field values are stored)

Once you will save and preview the app, you can see the result in the gallery control.

Example – 2:

• As you can see, there is a Text box control and a Gallery control. When a user searches any item in the search box, then the gallery filters and displays all the records based on the Person field, and that should be displayed in alphabetical order (Descending).
• For example, I searched the item or title as IT in the search box, then the gallery filtered and showed only the IT records where the person field appeared in alphabetic descending order as shown in the below screenshot.
• To do so, select the gallery and set its Items property to the below code:
``````Items = SortByColumns(
Filter(
'Scheduled Events',
"PersonName",
'Event Manager'.DisplayName
),
StartsWith(
Title,
TextInput1.Text
)
),
"PersonName",
Descending
)``````

Where,

1. ‘Scheduled Events’ = Specify the SharePoint list name
2. “PersonName” = Provide a unique name where the SharePoint Person values will store
3. ‘Event Manager’ = Specify the SharePoint Person field name that you want to sort
4. Title = Single line of text field that a user will search the title in the text box
5. TextInput1 = Text input control name where a user can search the title
6. Descending = Specify the order that you want to display in the gallery control

Save and Preview the app. Search any item or title in the search box, then the result you can see in the gallery control.

Example – 3:

This is another scenario to sort the app based on a People Column in the SharePoint list.

• For this scenario also, I have used the same SharePoint list named IT Help Desk. You can see there is a default column i.e. Created By with Person field data type. Also, this list has some below records.
• Now what I want to do is, I would like to display records that who created on their own. Suppose, I created some records, then only those records will appear in the app. I cannot see any other user’s records in the app.
• Moreover, the records will sort based on the SharePoint Created field.
• As I logged in with the user “Preeti“, that’s why the gallery shows all the records that are created by Preeti only as shown below.
• To achieve this, select the gallery and set its Items property as:
``````Items = Sort(
Filter(
'IT Help Desk',
'Created By'.DisplayName = "Preeti Sahu"
),
Created,
Descending
)``````

Where,

1. Preeti Sahu” = Provide the user name whose record you want to view in the Power Apps gallery. You must ensure to put the email within an inverted comma (” “).
2. Created = By default, it is a Date time field
3. Descending = Specify the order that you want to view in the gallery
• Or you can try the below formula by providing the user’s Email address:
``````Items = Sort(
Filter(
'IT Help Desk',
'Created By'.Email = "Preeti@****************.onmicrosoft.com"
),
Created,
Descending
)``````

Where,

Preeti@****************.onmicrosoft.com” = You need to specify the email address for the specific user of whom you want to display the record in the gallery control. You must ensure to put the email within an inverted comma (” “).

• But the above formulas may cause a Delegation warning issue in the app, in order to overcome this issue, we can follow the below processes.
1. First, we will create a Power AppsCollection and store all the SharePoint records in that collection. Also, we will set a variable where it can store the current user information. Set the below code on App’s OnStart property:
``````OnStart = ClearCollect(
HelpDeskCollection,
'IT Help Desk'
);
Set(
myEmail,
Office365Users.MyProfile().Mail
)``````

Where,

1. HelpDeskCollection = Provide a new collection name
2. ‘IT Help Desk’ = Provide the SharePoint List name
3. myEmail = Specify a Variable name

Before applying the above formula, you must ensure to add the Office365Users connector to the app. Otherwise, you will get the error in the above formula.

• Next, select the gallery and set its Items property to the below code:
``````Items = Sort(
Filter(
HelpDeskCollection,
'Created By'.Email = myEmail
),
Created,
Descending
)``````

Refer to the below screenshot.

• Once everything is done, just save and publish the app. Preview the app and click on the Run OnStart option. Then you can view the result in the gallery control.

This is how to work with Power Apps sort by person column.

Also, you may like the below Dataverse and Power Apps Tutorials:

In this Power Apps tutorial, We discussed what the Power Apps Sort function is, what is Power Apps SortByColumns function, and their all syntaxes. Also, we covered these below topics:

• Power Apps Sort Gallery
• Power Apps sort distinct filter
• Power Apps sort dropdown choices
• Power Apps sort by choice column
• Power Apps sort ascending descending
• Power Apps sortbycolumns choice column
• Power Apps sort and filter datatable
• Power Apps sort and filter on multiple columns
• Power Apps sort by specific value
• Power Apps sort by calculated field
• Power Apps sort by id
• Power Apps Sort Collection or Power Apps sort collection alphabetically
• Power Apps Sort Collections on Multiple columns
• Power Apps Sort Combobox
• Power Apps sort list box
• Power Apps Sort by Month
• Power Apps Sort Priority
• Power Apps Sort by Person Column