web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Need to filter a galle...
Power Apps
Unanswered

Need to filter a gallery by User Role. The gallery is currently filtered by a variable to reset, Cannot get both codes to work. HELP!

(0) ShareShare
ReportReport
Posted on by 6

Good morning all,

I am using the following tutorial to create a role based access to an editable grid app. (Designing A Role-Based User Interface In Power Apps - Matthew Devaney). 

But I have hit a wall with the gallery in trying to get it to filter for a specific role. (i.e. Employee, Manager, Administrator) 
The current column holding the data for the people is a people picker column in a SharePoint List. 
There are [2] connected datasets that are SharePoint Lists. 
1. Site Inspections (SharePoint List)
columns: 
a. LocationName
b. InspectionStatus
c. InspectedBy (People Picker)
d. InspectionDate

2. Technician Tracking (SharePoint List)
a. User (people Picker)
b. Role

This is the code I am trying to use in the gallery: 
If( varRole="Employee", Filter('Site Inspections', InspectedBy.DisplayName=varUser.DisplayName), 'Site Inspections' )
in conjunction with this code to reset the gallery : 

Filter('Site Inspections',varReset).

If I remove the { 
Filter('Site Inspections',varReset) } code and just use the code to filter for role, I can get it to work when I enter the employee email in the OnStart code, but then if I remove the employee email, it stops filtering. When I am in the app as an Admin, it does not filter for my role based on code, which I am guessing is because it specifically says "Employee", so does that mean I have to repeat that line of code for each role? 

Sorry for all the questions, and appreciate any help with this. 



Categories:
I have the same question (0)
  • mmbr1606 Profile Picture
    14,615 Super User 2026 Season 1 on at

    hey @A2theZ 

     

    try something like this please:

    // Fetch the role of the current user
    varUserRole = LookUp('Technician Tracking', User.DisplayName = CurrentUser.DisplayName, Role)
    
    // Filter the Site Inspections list based on the role
    Filter('Site Inspections', 
     LookUp('Technician Tracking', User.DisplayName = InspectedBy.DisplayName, Role) = varUserRole
    )

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • daved3 Profile Picture
    137 on at

    Hello -  

     

    I am not sure what you are trying to do with the line

     

    Filter('Site Inspections',varReset).

     

    However, I took a look at the link, 

     

    In the App - OnStart section, he is getting the logged in user and setting that to the varUser variable.  So depending who is logged in, the varUser will reflect the logged in user.

     

    // Obtain username and email of the logged-in user
    Set(varLoggedInUser, User());

    // Find the user with a matching email in the App Users list
    With(
    {wUserRecord: LookUp('App Users', User.Email=varLoggedInUser.Email)}

     

    Since testing this would require login in with different accounts, he says to test instead enter the employee email in the OnStart code (hard code the email).  This way you can see what these user would see.

     

    Thanks

    Dave

     

    Please click Accept  as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up .

  • A2theZ Profile Picture
    6 on at

    Hello @mmbr1606 ,
    Would i add that code in the App Onstart  or do I enter that in the gallery items screen? 

  • daved3 Profile Picture
    137 on at

    Hello @A2theZ 

     

    I went thru the tutorial - (Designing A Role-Based User Interface In Power Apps - Matthew Devaney). 

     

    I worked well for me.  I am just not sure what you are trying to do or what the issue is you are having.  If you can provide more info on what you want to do, someone may be able to offer more help.

     

    Regards

    Dave

  • A2theZ Profile Picture
    6 on at

    I think the issue is that my gallery is a little more complex, I have set it up as an editable grid with collections. 
    The gallery has buttons set up to save edits, reset edits, and create a new entry. 

    This is the only code attached to the gallery currently. 

    Filter('Site Inspections',varReset

    When I try to add the following code [ If( varRole="Employee", Filter('Site Inspections', InspectedBy.DisplayName=varUser.DisplayName), 'Site Inspections' ) ] to delegate the view of the gallery to a users designated role, I am getting an error. I know I need to keep that varReset code so that updates to the gallery show, but of course I need to also connect the user role to their specific items in the SharePoint list. 

    My app is not designed in the same way as the tutorial at the moment. 

  • daved3 Profile Picture
    137 on at

    Thanks for the additional info.  

     

    I am using the code you have above in the "items" property of the gallery:

     

    If( varRole="Employee", Filter('Site Inspections', InspectedBy.DisplayName=varUser.DisplayName), 'Site Inspections' ) ]

     

    If in the OnStart area the following is set to

     

    {wUserRecord: LookUp('App Users', User.Email=varLoggedInUser.Email)}

     

    then the gallery shows all the records as I am not an employee.

     

    if I change the code to one of the users in my environment who is listed as an employee, then the gallery only shows the items for that employee.

     

    {wUserRecord: LookUp('App Users', User.Email="useremail@domain.com")}

     

    I am not sure how you are using the varReset - is this a variable that you are setting somewhere else in your code ?

  • A2theZ Profile Picture
    6 on at

    @daved3 It was part of the original code for the first tutorial of setting up an editable Grid. I will keep working on it and respond back with updates. I thank you all for your time. It is truly appreciated. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 536

#2
WarrenBelz Profile Picture

WarrenBelz 426 Most Valuable Professional

#3
Haque Profile Picture

Haque 305

Last 30 days Overall leaderboard