SharePoint has a couple of built-in filters for column values: [Today] and [Me]. These allow users to filter views by dynamic data. For example you can create a view called AssignedToMe and set a filter like so:
Using this approach site admins don’t need to create views specific to each user, but can use the [Me] filter on a single view that applies to each individual user. As a user visits the view, they see only the records that are specific to them.
How does one do this in PowerApps when filtering data? Good question. This came up during our Minnesota SharePoint User Group (MNSPUG) meeting today and good old Brian Caauwe knew the answer: rather than using [Me] we use the User function in PowerApps.
On a gallery or data table object, our Items property might have a formula something like this:
Items = Filter(‘IT Request’, AssignedTo.DisplayName=User().FullName)
Note: When bringing fields over from SharePoint, PowerApps translates the CreatedBy and ModifiedBy fields to something a little different. That might be a little confusing when getting started.
- CreatedBy –> Author
- ModifiedBy –> Editor
Good questions from the attendees today and good catch by Brian with the User() answer.
*Disclaimer* – This post based on Preview version of PowerApps. I’ll make every effort to update with any changes and verify when PowerApps is released.
One of the powerful features in PowerApps for SharePoint users is the ability to create an app from a SharePoint list. When using this feature, PowerApps creates three screens for us to start with: A Browse screen, a View screen, and a New/Edit Item screen.
The Browse screen contains a Gallery control – which displays the contents of a list. By default it shows ALL items in a list. This might be fine for some business needs – especially with the inclusion of the search functionality also built into the default screen. Some use cases however may look for a filtered view of a list.
The Short Version
The browse screen is set up to show all items, as well as take input from the search box. I’m going to change the list to display all items where the Request Type is a certain value.
- Select the Gallery on the browse page
- Change the Items formula from search-based to filter-based:
SortByColumns(Search(‘Service Requests‘, TextSearchBox1_1.Text, “Comments”, “Notes”, “Title”, “Title”), “Comments”, If(SortDescending1, Descending, Ascending))
SortByColumns(Filter(‘Service Requests’, ReqType.Value=”PEBKaC”), “Comments”, If(SortDescending1, Descending, Ascending))
- Items displayed on the screen should now be filtered by the Request Type.
- Similar to other methods in SharePoint (like CSR with JSLink) the field names seem to be using the internal name of the field. Above, when accessing the Request Type we needed to use ‘ReqType’.