Power BI - Sales report example with Row-Level Security (RLS)

 

Sales report example with Row-Level Security (RLS) .

Sales Data

Imagine you have a table called SalesData with these columns:

SalesIDRegionSalesAmountSalesRepEmail
1North5000alice@company.com
2South7000bob@company.com
3East6000charlie@company.com
4West8000diana@company.com
5North4000alice@company.com
6South9000bob@company.com

 Step-by-Step RLS Setup

1. Create Role

  • Go to Modeling → Manage Roles → Create Role.
  • Name it: SalesRepRole.

2. Apply Dynamic Filter

Use DAX to filter rows based on the logged-in user’s email:

[SalesRepEmail] = USERPRINCIPALNAME()

This ensures each sales rep only sees their own sales records.


3. Test in Power BI Desktop

  • Use View As → SalesRepRole.
  • Enter a test email (e.g., bob@company.com).
  • You should only see rows where SalesRepEmail = bob@company.com.

4. Publish to Power BI Service

  • Publish the report.
  • In the dataset settings → Security, assign users to the SalesRepRole.

Example Outcome

  • Alice (alice@company.com) logs in → sees only North region sales (SalesID 1 & 5).
  • Bob (bob@company.com) logs in → sees only South region sales (SalesID 2 & 6).
  • Charlie (charlie@company.com) → sees East region sales (SalesID 3).
  • Diana (diana@company.com) → sees West region sales (SalesID 4).

 Why This Matters

  • Dynamic RLS scales easily across hundreds of users.
  • No need to manually create separate reports for each sales rep.
  • Ensures data security and personalized insights.

Let’s extend the sales report RLS example to include manager-level security, which is a common real-world .


Sales & Manager Data

SalesData Table

SalesIDRegionSalesAmountSalesRepEmail
1North5000alice@company.com
2South7000bob@company.com
3East6000charlie@company.com
4West8000diana@company.com
5North4000alice@company.com
6South9000bob@company.com

ManagerMapping Table

ManagerEmailSalesRepEmail
manager_north@company.comalice@company.com
manager_south@company.combob@company.com
manager_east@company.comcharlie@company.com
manager_west@company.comdiana@company.com

Step-by-Step Manager-Level RLS

1. Create Relationship

  • Relate SalesData[SalesRepEmail] to ManagerMapping[SalesRepEmail].

2. Define Role

  • Go to Modeling → Manage Roles → Create Role.
  • Name it: ManagerRole.

3. Apply Dynamic Filter

Use DAX to filter based on the logged-in manager’s email:

[ManagerEmail] = USERPRINCIPALNAME()

This ensures managers only see sales records for their assigned reps.


4. Test in Power BI Desktop

  • Use View As → ManagerRole.
  • Enter a test email (e.g., manager_south@company.com).
  • You should see only Bob’s sales (SalesID 2 & 6).

5. Publish & Assign

  • Publish to Power BI Service.
  • In dataset Security, assign managers to the ManagerRole.

 Example Outcome

  • manager_north@company.com → sees Alice’s sales (North region).
  • manager_south@company.com → sees Bob’s sales (South region).
  • manager_east@company.com → sees Charlie’s sales (East region).
  • manager_west@company.com → sees Diana’s sales (West region).

 Key Takeaway

  • Sales reps see only their own data (via SalesRepRole).
  • Managers see their team’s data (via ManagerRole).
  • This layered RLS setup is scalable and interview-ready — it shows you understand both individual-level and hierarchical-level security.



Comments