Can you sort the Power Apps Gallery by SharePoint Person column? Of course, Yes!
In this Power Apps tutorial, I will discuss how to sort gallery by person column in Power Apps with various examples.
Also, we will explore how to overcome the delegation issue while working with Power Apps sort gallery by person column.
How to Sort Gallery by Person Column in Power Apps
Refer to the scenarios below to sort the Power Apps gallery by Person Column.
Example – 1:
1. The screenshot below represents a SharePoint list named Scheduled Events. This list has various fields with various data types as:
|Title||Single line of text|
|Department||Choice [IT, MARKETING, HR, FINANCE]|
|Location||Choice [Pentagon, Decagon, Octagon, Nonagon]|
|Start Date||Date and time|
Refer to the image below:
2. I want to sort the Person field (Event Manager) in a Power Apps gallery control, which will look like the screenshot below.
3. To do so, select the Gallery control and apply the below code on its Items property as:
Items = SortByColumns( AddColumns( 'Scheduled Events', "PersonsName", 'Event Manager'.DisplayName ), "PersonsName" )
- “PersonsName” = Provide a unique name where the SharePoint person values will store
- ‘Event Manager’ = SharePoint Person field
4. Then, select the label inside the gallery and set its Text property as:
Text = "Manager: " & ThisItem.PersonsName
“Manager: “ = This is the text that will be displayed in the label control
5. Save, Publish, and Preview the app. The Power Apps gallery control has been sorted by Person column.
Example – 2:
1. In Power Apps, there is a Text box control and a Gallery control. When a user searches for any item in the search box, the gallery filters and displays all the records based on the Person field, which should be displayed alphabetically (Descending).
2. 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 screenshot below.
3. To do so, select the gallery and set its Items property to the below code:
Items = SortByColumns( Filter( AddColumns( 'Scheduled Events', "PersonName", 'Event Manager'.DisplayName ), StartsWith( Title, TextInput1.Text ) ), "PersonName", Descending )
- ‘Scheduled Events’ = SharePoint list name
- “PersonName” = Provide a unique name where the SharePoint Person values will store
- ‘Event Manager’ = SharePoint Person field
- TextInput1 = Text input control name where a user can search the title
- Descending = Specify the order
4. Save and Preview the app. The gallery will sort and display all the records depending on the Person field [Descending order] when you enter any item or title in the search box.
Example – 3:
This is another scenario to sort the Power Apps Gallery based on the SharePoint People Column.
1. I have used a SharePoint list named IT Help Desk. This list has a Default column called Created By with Person data type.
2. I now want to show records only created by the current user. Let’s say you created some records; the app will only display those you create. The app does not allow me to view any other user’s records.
3. Additionally, the items will be arranged according to the SharePoint Created column.
4. As I logged in with the user “Preeti“, the gallery shows all the records created by Preeti only, as shown below.
5. 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 )
- “Preeti Sahu” = Provide the user name whose record you want to view in the Power Apps gallery. You must put the email within an inverted comma (” “).
- Created = By default, it is a Date-time field
- Descending = Specify the order that you want to view in the gallery
6. 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 )
“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 put the email within an inverted comma (” “).
7. 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.
8. First, we will create a Power Apps Collection 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 the App’s OnStart property:
OnStart = ClearCollect( HelpDeskCollection, 'IT Help Desk' ); Set( myEmail, Office365Users.MyProfile().Mail )
- HelpDeskCollection = Provide a Collection name
- ‘IT Help Desk’ = SharePoint List name
- myEmail = Specify a Variable name
NOTE:Before applying the above formula, add the Office365Users connector to the app. Otherwise, you will get the error in the above formula.
9. 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 screenshot below.
10. Once everything is done, 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 sort gallery by person column in Power Apps.
This Power Apps tutorial explores everything about how to sort gallery by person column in Power Apps [both ascending and descending order].
Also, we saw how to overcome the delegation issue while working with Power Apps sort gallery by person column with various scenarios.
Also, you may like some more Power Apps tutorials:
- Sort by Columns in Power Apps
- Sort Dropdown Choices Alphabetically in Power Apps
- Sort Power Apps Gallery By ID
- Power Apps Sort Distinct Filter
- Add New Row in Power Apps Gallery Control
- Power Apps Gallery Pagination
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