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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
debenaire
Helper I
Helper I

Dynamic RLS with multiple tables

Hi there. I have a reasonably complicated dynamic RLS which i am trying to resolve through dax. Attached is the schema.

 

The premise is the Id in the user table is the USERRPINCIPALNAME

The user has a a list of companies they are allowed access to in the USERALLOWED table

These companies have a relevant ID called InstanceId-CRMId that gets passed into a site list and on to the report to limit the data.

 

The issue i am haivng is i do not want to have to use bidirectional relationships

There iaremany to many relationships

Performance is poor

I cannot seem to get the RLS to properly work and the sites table isnt filtering when I add ID = USERPRINCIALNAME() in the user table.

 

Can someone suggest specifc dax for this use case please??? I have looked at some RADACAD posts on this example but can't work it out. Thanks in advance!!Screenshot.png

 

 

1 ACCEPTED SOLUTION

Actually, I had some time now. Here is original post, tweaked for User : UserAllowedCompany to have M:M relationship.

 

The filter from User will propogate as long as it travels through a single direction filter. So, either one --> many relationships from the one side OR single filter direction many --> many relationship from the left (A) side of A filters B.

 

As you've noted, it doesn't work nicely when traveling from the other direction, many --> one, like UserAllowedCompany (many) --> (one) Company.

 

To get this working without relying on bidirection filtering, you'll need to define an RLS filter rule on Company. Note that once that is working, it looks like the RLS filter will propogate throughout the rest of your model by leveraging the filter directions on (the rest showing are one --> many relationships).

 

Something like the following should work as the filter on Company:

CALCULATE( 
  NOT ISEMPTY( UserAllowedCompany ), 
  User[Id] = USERPRINCIPALNAME() 
)

Note that, even though you should also have the User[Id] = USERPRINCIPALNAME() filter on User, the RLS filters aren't evaluated in order, so you need to re-incorporate the underlying USERPRINCIPALNAME() filter any time you are defining a new RLS filter.

 

Here are some screenshots with a dummy model similar to yours in case helpful.

 

MarkLaf_0-1698783856458.png

MarkLaf_1-1698783898564.pngMarkLaf_2-1698783969210.png

 

MarkLaf_3-1698771346731.pngMarkLaf_4-1698771363428.png

MarkLaf_3-1698784114825.png

 

View solution in original post

5 REPLIES 5
debenaire
Helper I
Helper I

@MarkLaf  thank you so much for your help with this.

MarkLaf
Memorable Member
Memorable Member

The filter from User will propogate as long as it travels through one --> many relationships from the one side.

 

As you've noted, it doesn't work nicely when traveling from the other direction, many --> one, like UserAllowedCompany (many) --> (one) Company.

 

To get this working without relying on bidirection filtering, you'll need to define an RLS filter rule on Company. Note that once that is working, it looks like the RLS filter will propogate throughout the rest of your model through one --> many relationships.

 

Something like the following should work as the filter on Company:

CALCULATE( 
  NOT ISEMPTY( UserAllowedCompany ), 
  User[Id] = USERPRINCIPALNAME() 
)

Note that, even though you should also have the User[Id] = USERPRINCIPALNAME() filter on User, the RLS filters aren't evaluated in order, so you need to re-incorporate the underlying USERPRINCIPALNAME() filter any time you are defining a new RLS filter.

 

Here are some screenshots with a dummy model similar to yours in case helpful.

MarkLaf_0-1698771109640.png

MarkLaf_5-1698771515344.png

 

MarkLaf_3-1698771346731.pngMarkLaf_4-1698771363428.png

 

MarkLaf_6-1698771640486.png

 

@MarkLaf  thank you so much!! My model has many to many from user to UserAlkowedCompany because the id between them is not the user Id but the Licensee-UserRoleId which can be assigned to many users.  Does this make a difference as this is not working in my model. Thanks 

Actually, I had some time now. Here is original post, tweaked for User : UserAllowedCompany to have M:M relationship.

 

The filter from User will propogate as long as it travels through a single direction filter. So, either one --> many relationships from the one side OR single filter direction many --> many relationship from the left (A) side of A filters B.

 

As you've noted, it doesn't work nicely when traveling from the other direction, many --> one, like UserAllowedCompany (many) --> (one) Company.

 

To get this working without relying on bidirection filtering, you'll need to define an RLS filter rule on Company. Note that once that is working, it looks like the RLS filter will propogate throughout the rest of your model by leveraging the filter directions on (the rest showing are one --> many relationships).

 

Something like the following should work as the filter on Company:

CALCULATE( 
  NOT ISEMPTY( UserAllowedCompany ), 
  User[Id] = USERPRINCIPALNAME() 
)

Note that, even though you should also have the User[Id] = USERPRINCIPALNAME() filter on User, the RLS filters aren't evaluated in order, so you need to re-incorporate the underlying USERPRINCIPALNAME() filter any time you are defining a new RLS filter.

 

Here are some screenshots with a dummy model similar to yours in case helpful.

 

MarkLaf_0-1698783856458.png

MarkLaf_1-1698783898564.pngMarkLaf_2-1698783969210.png

 

MarkLaf_3-1698771346731.pngMarkLaf_4-1698771363428.png

MarkLaf_3-1698784114825.png

 

It should still work similar to my solution. Just ensure that the M:M has filtering direction set where User filters UserAllowedCompany.

 

That said, I would recommend changing query to join the User Id onto UserAllowedCompany and then setting up a 1:M relationship between User and UserAllowedCompany as set up in the dummy model I showed.  

 

If updating the query isn't possible or desireable, I can update my original post to include a M:M relationship between User and UserAllowedCompany. Just let me know

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.