Filter Power Apps Gallery by Current User

Do you know how to Filter Gallery by Current User in Power Apps? No problem.

This Power Apps tutorial explains everything about Power Apps Filter Gallery by Current User with a few examples.

Power Apps Filter Gallery by Current User

Let’s see how to filter Power Apps Gallery by Current User using various examples. There are different approaches to filtering the gallery by the current user in Power Apps. Such as:

Method – 1: (Using User Display Name or User Email Address)

  • The below screenshot represents a SharePoint List (Blog Sites). This list has various columns with various data types:
    • Title = This is a SharePoint Default column with a Single line of text data type
    • Site URL = Single line of text
    • Site Rank = Single line of text
    • Active Or Inactive = Yes/No
    • Created By = This is a SharePoint Default column with a Person or group data type
How to Filter Gallery by Current User in Power Apps
How to Filter Gallery by Current User in Power Apps
  • Now, I would like to filter the Power Apps Gallery based on the current user. This means that the current user can only view their records when they open the app.
Power Apps Filter Gallery by Current User
Power Apps Filter Gallery by Current User
  • To achieve this, select the Power Apps Gallery control and apply the code below on its Items property as:
Items = Filter(
    'Blog Sites',
    'Created By'.DisplayName = "Preeti Sahu"
)

Where,

  1. Blog Sites‘ = SharePoint List Name
  2. Created By‘ = Person column name
  3. Preeti Sahu” = Specify the display name of the current user
How to Filter Power Apps Gallery by Current User
How to Filter Power Apps Gallery by Current User
  • Also, you can follow the code below:
Items = Filter(
    'Blog Sites',
    'Created By'.Email = "preeti@tsinfotechnologies.onmicrosoft.com"
)

Where,

preeti@tsinfotechnologies.onmicrosoft.com” = Specify the Email address of the current user

How to Filter PowerApps Gallery by Current User
How to Filter PowerApps Gallery by Current User

This is the first approach that we can try to filter the gallery by the current user in Power Apps.

See also  Delete All Records From Dataverse Table [With Examples]

Check out: Power Apps Modern Information Button Control [Complete Guide]

Method – 2: (Using Power Apps With Function)

Now we will see the second approach to filter the Power Apps Gallery by the current user.

  • The below image represents a Power Apps gallery that displays only the records of the current user (Preeti Sahu). For this, we will use Power Apps With function.
PowerApps Filter Gallery by Current User
PowerApps Filter Gallery by Current User
  • To work around this, select the Gallery control and set its Items property as:
Items = With(
    {varCurrentUserEmail: User().Email},
    Filter(
        'Blog Sites',
        'Created By'.Email = varCurrentUserEmail
    )
)

Here, the Power Apps With function determines the User().Email value and saves the result in varCurrentUserEmail.

Also, if you want to provide the user Display name, then you can specify:

  • User().DisplayName instead of User().Email
  • ‘Created By’.DisplayName instead of ‘Created By’.Email
How to Filter Gallery by Current User in PowerApps
How to Filter Gallery by Current User in PowerApps

This is the second approach to filter the Power Apps gallery by the current user.

Read: How to Set Gallery First Item in Power Apps Display Form

Method – 3: (Using Power Apps Global Variable)

Next, we will discuss the third approach to filter the Power Apps Gallery by the current user.

  • This Third method involves storing the email address in a Power Apps variable and using that variable as a point of reference when calling the filter function.
  • First, we will declare a global variable on App’s OnStart property as:
OnStart = Set(varUserEmail, User().Email)

Where,

varUserEmail = Global variable name

Power Apps filter gallery control by current user
Power Apps filter gallery control by current user
  • Then, select the Gallery control and set its Items property to the code below:
Items = Filter(
    'Blog Sites',
    'Created By'.Email = varUserEmail
)

Where,

  1. Blog Sites‘ = SharePoint List Name
  2. varUserEmail = Specify the global variable that you have created on App’s OnStart property
PowerApps filter gallery control by current user
PowerApps filter gallery control by current user
  • Finally, Save and Publish the app. Close and reopen the app once again. You can see that the gallery will show all of the filtered records according to the person currently logged in.
See also  Power Apps Attachment Control - How to Use

This is the third approach to filter the Power Apps gallery by the current user using the variable.

Have a look: Power Apps Modern Tab List Control [Everything in Detail]

Method – 4: (Using SharePoint Person Column)

  • Let’s take a different scenario here. You can see there is a SharePoint Online list named TSInfo Attachments. This list has below columns:
    • ID = Default Number column
    • Title = Default Single line of text column
    • Attachment Types = Choice
    • Attachment Costs = Currency
    • Attachment Created Date = Date and time
    • Book Author = Person or group
    • IsReceived = Yes/No
  • Next, I would like to filter the Power Apps gallery based on the Book Author column (Current user).
Power Apps filter gallery current user
Power Apps filter gallery current user
  • To achieve this, apply the code below on Gallery’s Items property:
Items = Filter(
    'TSInfo Attachments',
    'Book Author'.Email = User().Email
)

Where,

Book Author‘ = SharePoint Person field name

Power Apps gallery filter by current user
Power Apps gallery filter by current user

This is how to filter Power Apps Gallery Control by Current user.

Additionally, you may like some more Power platform tutorials:

In this Power Apps tutorial, we learned about Power Apps Filter Gallery by Current User with a few examples.

>