Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
obriaincian
Resolver I
Resolver I

Dynamic Row Level Security

Hi All,

 

I'm a bit puzzled and cannot get my head around how to set up dynamic RLS for the below example.

 

I want to use USERPRINCIPALNAME() and determine if the user is a manager or director (use the roles table for this).

If they are a director I want to filter the Director Email in the data table for the email returned by USERPRINCIPALNAME(). If they are a manager I want to filter the Manager Email for the email returned by USERPRINCIPALNAME(). 

 

Any help will be greatly appreciated

 

 

I have 2 tables (my dataset is confidential so I'll create dummy data below)

 

Table 1: Roles Table

NameEmailRole
Michael DunneMichael@123.ieDirector
Ann BroganAnn@123.ieManager
Julie MurrayJulie@123.ieManager
Ben MarshBen@123.ieDirector

 

Table 2: Data Table

EmployeeEmailManager EmailDirector Email
Michael DunneMichael@123.ieMichael@123.ieMichael@123.ie
Ann BroganAnn@123.ieAnn@123.ieMichael@123.ie
Julie MurrayJulie@123.ieJulie@123.ieMichael@123.ie
Stephen FryStephen5@123.ieAnn@123.ieBen@123.ie
1 ACCEPTED SOLUTION

@obriaincian 

VAR _roles=SELECTCOLUMNS(FILTER('Roles Table',[Email]=USERPRINCIPALNAME()),"@Role",[Role])
VAR _filter = SWITCH(TRUE(),
"Director" IN _roles && "Manager" IN _roles, [Director Email] = USERPRINCIPALNAME() && [Manager Email] =USERPRINCIPALNAME(),
"Director" IN _roles, [Director Email] = USERPRINCIPALNAME(),
"Manager" IN _roles, [Manager Email] =USERPRINCIPALNAME(),
FALSE())
RETURN _filter

If required use || insted of && in the red marked place. If you use AND (&&), data will be available only both conditions are true. I think you need OR (||) condition.

nandukrishnavs_0-1692079295968.png

 


Regards,
Nandu Krishna

View solution in original post

3 REPLIES 3
nandukrishnavs
Community Champion
Community Champion

@obriaincian  Try below DAX expression 

 

VAR _role=MAXX(FILTER('Roles Table',[Email]=USERPRINCIPALNAME()),[Role])
VAR _filter = SWITCH(_role,
"Director", [Director Email] = USERPRINCIPALNAME(),
"Manager",[Manager Email] =USERPRINCIPALNAME(),
FALSE())
RETURN _filter

nandukrishnavs_0-1691742825259.png

 

 


Regards,
Nandu Krishna

@nandukrishnavs thank you, this is great, can I ask you one last question.

 

I also have instances where one user can be both a Director and Manager, in this instance I'd want to filter the data for where [Director Email] = USERPRINCIPALNAME() &&

                        [Manager Email] = USERPRINCIPALNAME() 

 

I modified the code to look like this but it's not working

 

VAR _role=MAXX(FILTER('Roles Table',[Email]=USERPRINCIPALNAME()),[Role])
VAR _filter = SWITCH(_role,
"Director and Manager", [Workstream DRI Email] = USERPRINCIPALNAME() && [Hiring Manager Email] =USERPRINCIPALNAME(),
"DRI", [Workstream DRI Email] = USERPRINCIPALNAME(),
"Hiring Manager",[Hiring Manager Email] =USERPRINCIPALNAME(),
FALSE())
RETURN _filter

 

Thanks

@obriaincian 

VAR _roles=SELECTCOLUMNS(FILTER('Roles Table',[Email]=USERPRINCIPALNAME()),"@Role",[Role])
VAR _filter = SWITCH(TRUE(),
"Director" IN _roles && "Manager" IN _roles, [Director Email] = USERPRINCIPALNAME() && [Manager Email] =USERPRINCIPALNAME(),
"Director" IN _roles, [Director Email] = USERPRINCIPALNAME(),
"Manager" IN _roles, [Manager Email] =USERPRINCIPALNAME(),
FALSE())
RETURN _filter

If required use || insted of && in the red marked place. If you use AND (&&), data will be available only both conditions are true. I think you need OR (||) condition.

nandukrishnavs_0-1692079295968.png

 


Regards,
Nandu Krishna

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.