How to Sort Gallery by Person Column in Power Apps?

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:

ColumnData type
TitleSingle line of text
DepartmentChoice [IT, MARKETING, HR, FINANCE]
LocationChoice [Pentagon, Decagon, Octagon, Nonagon]
Event ManagerPerson
Start DateDate and time

Refer to the image below:

Power Apps sort by person column
Power Apps sort by person column

2. I want to sort the Person field (Event Manager) in a Power Apps gallery control, which will look like the screenshot below.

How to Sort Gallery by Person Column in Power Apps

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"
)

Where,

  1. “PersonsName” = Provide a unique name where the SharePoint person values will store
  2. ‘Event Manager’ = SharePoint Person field
Sort Gallery by Person Column in Power Apps
Sort Gallery by Person Column in Power Apps

4. Then, select the label inside the gallery and set its Text property as:

Text = "Manager: " & ThisItem.PersonsName

Where,

“Manager: “ = This is the text that will be displayed in the label control

Power Apps Sort Gallery by Person Column

5. Save, Publish, and Preview the app. The Power Apps gallery control has been sorted by Person column.

See also  How to Migrate Power Apps from One Tenant to Another?

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.

PowerApps Sort Gallery by Person Column

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
)

Where,

  • ‘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
Power Apps sort by person field

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.

See also  Power Apps Data Table Conditional Formatting

3. Additionally, the items will be arranged according to the SharePoint Created column.

Power Apps sort by people column

4. As I logged in with the user “Preeti“, the gallery shows all the records created by Preeti only, as shown below.

Sort and filter Power Apps gallery by Person column

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
)

Where,

  1. 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 (” “).
  2. Created = By default, it is a Date-time field
  3. Descending = Specify the order that you want to view in the gallery
Sort by people field in Power Apps

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
)

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 put the email within an inverted comma (” “).

Sort by person column in PowerApps
Sort by person column in PowerApps

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
)

Where,

  • 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.
PowerApps Sort by people picker
PowerApps Sort by people picker

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.

Power Apps Sort by people picker
Power Apps Sort by people picker

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.

See also  How to Remove Duplicate Rows From a Power Apps Collection?

This is how to sort gallery by person column in Power Apps.

Conclusion

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:

>