Power Apps Filter by [Me]
In SharePoint, it’s easy to create a view that shows a list with a person field filtered to show [Me], so the items in the list are dynamically related to the current person looking at the list. In PowerApps though, it’s a little trickier because of the delegation error. Here’s the error that you may have come across in trying to do this in a gallery:
It does show me a list of my projects, but gives me a delegation error. I’m trying to filter the list, so that it only shows items where I am the Project Manager. Project Manager is a person field in this SharePoint list. More on delegation here. As of now, there are a couple of different workarounds you can do:
- Collect the list, and then use that collection in the gallery, and the same filter won’t give an error
- OR create an extra, text field in the SharePoint list, to store the person’s email address as text and filter by that.
Here are the steps for both:
Solution option 1: Collecting the list.
- At some point in the app, collect your list. Now, keep in mind that the larger your list, the longer this will take, and end users will not appreciate the delay. You can go to the first screen of your app, and use the OnStart or OnVisible property, and put this function in there. My SharePoint list is called ‘Projects’, so I just name the collection with the prefix ‘col’ in front of it. You’ll also want to initially capture the current user’s email address when they open the app, since this variable will also be necessary in avoiding the delegation error.
You can see that your collection has been created, by clicking the View menu, and then Collections.
- Then, take a look at the first screenshot at the top of the page. Simply change the source in that function, so the new function for Items in your gallery will be this:
Advanced side note: When you collect the list of projects, it is possible to filter it then, but you just can’t filter it by a people field or lookup field, or any other complex field type that will give you a delegation error.
Solution option 2: Creating an extra field (more of a pain)
- Create an extra field in your SharePoint list, to store the project manager’s email address. Keep in mind that if you already have a bunch of items in your list, you’ll have to populate all of those as well. In my list, I called this new column PM_Email.
- On the first screen in the app, go to the OnStart property, and add this function:
- In your form in PowerApps, you’ll have to set this field to default to the project manager’s email address. The card for PM Email has to be added to the form, but when you’re done setting it up, you can hide it. Add the card.
- In your form, you’ll need to know the name of the control where the project manager is selected. Not the card, but the actual control, like a combo box. Mine is called drpProjectMan, because I renamed it to give it a nice, useful name.
- Go to the card for the new PM_Email field. Select the card, and unlock it. For the Default property, use this:
- Then, go to the Visible property of the PM_Email data card, and set it to false. This will hide it on the form.
- From now on, for anyone filling out this form in PowerApps, it will automatically set the PM’s email in that field. Once you have the PM_Email field populated in the whole list, here’s how to change the filter in the gallery. (the one at the top of the page that had an error)
Notice that now with this new filter, it’s not necessary to use a collection, but you need that extra field in the list.
Are you brand new to PowerApps, and interested in getting started learning some fundamentals? Try out my
Beyond beginner? Check out my full (12 hour) PowerApps training class!