In the latest Power App that I am writing using Dataverse I wanted to filter data from a table on the currently logged in user. My programming back ground told me to find the logged in users GUID and use that as a filter within the app. This would have worked but there is a much simpler way to do this using Data Verse views.
Dataverse views enable us to define queries and filters in a way that is re-usable across multiple canvas apps and model driven apps. This is achieved without writing any code to create a filter.
1. Firstly lets look at the three records in the Leave Request table. You can see each record has a default field called 'Created By' and 'Owner' which is automatically populated.
2. Now the Canvas App is always accessible with a Microsoft 365 user and I want to filter the Leave Request table with the logged in user using a view. When inside the table settings select Views from the menu.
3. Inside the Views screen you will see current views created. Press the Add view button to create a new view.
4. Give the view a Name and Description.
5. Select the fields from the Leave Request table from the left and they will appear as columns. In my case I am selecting all fields.
6. Select Edit filters to filter the data for the view.
7. Select Add and Add row.
8. Now select the Owner row and change the condition to Equals current user. Press the OK button to accept.
9. You will notice the Filter by ... is Owner is current user . The rows in the view are only for the logged in user. Press the Save button and then the Publish to save the View and make it live..
10. Now back in the Canvas App you can see that the Leave Request table is displaying all of the records.
11. Change the Views option to the CurrentUser view that we created in Dataverse
12. Now that the view is set to CurrentUser the data table only shows data for the user that is logged in.
A view is easy to create without writing any code.
Only the data selected in the view is loaded into the Canvas App improving page load performance.
The current user is automatically chosen by the user running the Canvas App.