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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.