In this lab you will enforce row-level security to ensure that a salesperson can only analyze sales data for their assigned region(s).
In this lab you learn how to:
- Enforce row-level security
Lab story
This lab is one of many in a series of labs that was designed as a complete story from data preparation to publication as reports and dashboards. You can complete the labs in any order. However, if you intend to work through multiple labs, we suggest you do them in the following order:
- Prepare Data in Power BI Desktop
- Load Data in Power BI Desktop
- Model Data in Power BI Desktop
- Create DAX Calculations in Power BI Desktop, Part 1
- Create DAX Calculations in Power BI Desktop, Part 2
- Design a Report in Power BI Desktop, Part 1
- Design a Report in Power BI Desktop, Part 2
- Create a Power BI Dashboard
- Perform Data Analysis in Power BI Desktop
- Enforce Row-Level Security
Exercise 1: Enforce row-level security
In this exercise you will enforce row-level security to ensure a salesperson can only ever see sales made in their assigned region(s).
Task 1: Get started
In this task you will setup the environment for the lab.
Important: If you are continuing on from the previous lab (and you completed that lab successfully), do not complete this task; instead, continue from the next task.
- To open the Power BI Desktop, on the taskbar, click the Microsoft Power BI Desktop shortcut.
- To close the getting started window, at the top-left of the window, click X.
- To open the starter Power BI Desktop file, click the File ribbon tab to open the backstage view.
- Select Open Report.
- Click Browse Reports.
- In the Open window, navigate to the D:\PL300\Labs\10-row-level-security\Starter folder.
- Select the Sales Analysis file.
- Click Open.
- Close any informational windows that may open.
- To create a copy of the file, click the File ribbon tab to open the backstage view.
- Select Save As.
- If prompted to apply changes, click Apply.
- In the Save As window, navigate to the D:\PL300\MySolution folder.
- Click Save.
Task 2: Enforce row-level security
In this task you will enforce row-level security to ensure a salesperson can only see sales made in their assigned region(s).
- Switch to Data view.
- In the Fields pane, select the Salesperson (Performance) table.
- Review the data, noticing that Michael Blythe (EmployeeKey 281) has a UPN value of: michael-blythe@adventureworks.comRecall that Michael Blythe is assigned to three sales regions: US Northeast, US Central, and US Southeast.
- Switch to Report view.
- On the Modeling ribbon tab, from inside the Security group, click Manage Roles.
- In the Manage Roles window, click Create.
- In the box, replace the selected text with the name of the role: Salespeople, and then press Enter.
- To assign a filter, for the Salesperson (Performance) table, click the ellipsis (…) character, and then select Add Filter | [UPN].
- In the Table Filter DAX Expression box, modify the expression by replacing “Value” with USERPRINCIPALNAME().
USERPRINCIPALNAME() is a Data Analysis Expressions (DAX) function that returns the name of the authenticated user. It means that the Salesperson (Performance) table will filter by the User Principal Name (UPN) of the user querying the model.
- Click Save.
- To test the security role, on the Modeling ribbon tab, from inside the Security group, click View As.
- In the View as Roles window, check the Other User item, and then in the corresponding box, enter: michael-blythe@adventureworks.com
- Check the Salespeople role.
This configuration results in using the Salespeople role and impersonating the user with your Michael Blythe’s name.
- Click OK.
- Notice the yellow banner above the report page, describing the test security context.
- In the table visual, notice that only the salesperson Michael Blythe is listed.
- To stop testing, at the right side of the yellow banner, click Stop Viewing.
When the Power BI Desktop file is published to the Power BI service, you’ll need to complete a post-publication task to map security principals to the Salespeople role. You won’t do that in this lab.
- To delete the role, on the Modeling ribbon tab, from inside the Security group, click Manage Roles.
- In the Manage Roles window, click Delete.
- When prompted to confirm the deletion, click Yes, Delete.
- Click Save.
Task 3: Finish up
In this task you will complete the lab.
- Save the Power BI Desktop file.