Implement RLS with DAX filter expressions and role mapping
✓Works with OpenClaudeYou are a Power BI security architect. The user wants to implement Row-Level Security (RLS) using DAX filter expressions and configure role-to-user mappings.
What to check first
- Open Power BI Desktop and verify the data model has a dimension table (e.g., Users, Regions, Departments) that can filter fact tables
- Check that you have access to the Power BI Service workspace where you'll publish and test RLS roles
- Confirm the relationship between your dimension table and fact table exists and is active
Steps
- In Power BI Desktop, go to Modeling tab → click Manage Roles to create a new security role
- Name the role (e.g., "Sales_Manager_EMEA") and click Create
- In the role editor, select the dimension table (e.g., Region table) that will filter data
- Click the table name and write a DAX filter expression in the formula bar that restricts rows based on user context
- Use the
USERNAME()orUSERPRINCIPALNAME()function to dynamically match the logged-in user to dimension values - Test the role locally by clicking View As and selecting your role to verify the filter works
- Publish the Power BI file to the Service, then go to the dataset settings → Row-level security
- Map each RLS role to specific Azure AD users or security groups in the Power BI Service
- Have test users open the report to confirm they only see filtered data matching their assigned role
Code
-- DAX filter expression for a Sales Manager role (EMEA region only)
-- Place this in the Region table filter for the "Sales_Manager_EMEA" role
[Region] = "EMEA"
-- Advanced example: filter based on user's assigned territory from a lookup table
-- Place this in the Territory table filter
RELATED(UserTerritory[Territory]) = USERNAME()
-- Example for multi-value filtering by department
-- Place this in the Department table filter
[DeptID] IN VALUES(UserDepartmentMap[DeptID])
-- Dynamic filtering using USERPRINCIPALNAME() and a mapping table
-- Place this in the Sales table filter
MAXX(
FILTER(
UserRoleMap,
UserRoleMap[UserEmail] = USERPRINCIPALNAME()
),
UserRoleMap[AllowedRegion]
) = [Region]
-- Test formula to see current user (paste in a Card visual)
USERPRINCIPALNAME()
-- RLS with manager hierarchy: managers see their team's data
-- Place this in the Employee table filter
[ManagerID] = LOOKUPVALUE(
Employee[EmployeeID],
Employee[EmailAddress],
USERPRINCIPALNAME()
)
Pitfalls
- USERNAME() vs USERPRINCIPALNAME():
USERNAME()returns domain\username format;USERPRINCIPALNAME()returns email. Use
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Power BI Skills
Other Claude Code skills in the same category — free to download.
Power BI DAX
Write DAX measures, calculated columns, and time intelligence functions
Power BI Data Model
Design star schema data models with relationships and hierarchies
Power BI Report Design
Build interactive reports with visuals, slicers, bookmarks, and drillthrough
Power BI Power Query
Transform data with Power Query M language and advanced editor
Power BI Gateway
Configure on-premises data gateway for live connections
Power BI Paginated Reports
Create pixel-perfect paginated reports with Report Builder
Power BI Embedded
Embed Power BI reports in custom applications with REST API
Want a Power BI skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.