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
Anonymous
Not applicable

Dynamic RLS with many to many relationship

Hi, I would like to set up a Dynamic RLS with many to many relationship. Any advise would be greatly appreciated!

 

User access list 

User EmailMarketSpecies
John@gmail.comAllSwine
Patrick@gmail.comThailand

Ruminants

Patrick@gmail.comMalaysiaPoultry
Elise@gmail.comThailandAll
Elise@gmail.comJapanSwine

 

Data Set:

MarketSpeciesSales
ThailandSwine100
ThailandRuminants86
ThailandPoultry45
MalaysiaSwine12
MalaysiaRuminants57
MalaysiaPoultry46
JapanSwine31
JapanRuminants256
JapanPoultry

384

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous 

This is my idea. You may give it a try!

 

1. Transform the UserAccessList table into the following structure: Replace "All" with all possible markets and species, then combine market and species to create a new key column in both UserAccessList table and Sales table. (To learn about how to transform the data with Power Query, you can download my sample .pbix file attached at bottom of this reply.) 

vjingzhanmsft_0-1740625162023.png

vjingzhanmsft_1-1740625184172.png

 

2. Create a many-to-many relationship between Sales table and UserAccessList table, set up the cross-filter direction to Single (UserAccessList filters Sales).

vjingzhanmsft_2-1740625241964.png

 

3. Create RLS role and set DAX rule on UserEmail column. Use UserPrincipalName() function for dynamic RLS. 

vjingzhanmsft_3-1740625273312.png

4. Publish the report to Power BI Service, go to Security page of the semantic model to add users to the corresponding role. 

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

If the RLS is set up correctly, each person's view should be as follows:

John's View  
MarketSpeciesSales
ThailandSwine100
MalaysiaSwine12
JapanSwine31
   
Patrick's View 
MarketSpeciesSales
ThailandRuminants86
MalaysiaPoultry46
   
Elise's View  
MarketSpeciesSales
ThailandSwine100
ThailandRuminants86
ThailandPoultry45
JapanSwine31
Anonymous
Not applicable

Hi @Anonymous 

This is my idea. You may give it a try!

 

1. Transform the UserAccessList table into the following structure: Replace "All" with all possible markets and species, then combine market and species to create a new key column in both UserAccessList table and Sales table. (To learn about how to transform the data with Power Query, you can download my sample .pbix file attached at bottom of this reply.) 

vjingzhanmsft_0-1740625162023.png

vjingzhanmsft_1-1740625184172.png

 

2. Create a many-to-many relationship between Sales table and UserAccessList table, set up the cross-filter direction to Single (UserAccessList filters Sales).

vjingzhanmsft_2-1740625241964.png

 

3. Create RLS role and set DAX rule on UserEmail column. Use UserPrincipalName() function for dynamic RLS. 

vjingzhanmsft_3-1740625273312.png

4. Publish the report to Power BI Service, go to Security page of the semantic model to add users to the corresponding role. 

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

Anonymous
Not applicable

Thank you Jingzhan,

 

May I know what is the purpose of having DimMarket and DimSpecies tables? Do they serve any purpose, given the filtering is flowing from the UserAccessList through the many to many relationship?

 

Additionally, I am setting up this access for over a 100 users, 30 countries and 20 species. For some users, they only need filter to either market, or species data. The list is going to be very long if I have to list down all countries/species combinations.

Anonymous
Not applicable

Please check this, modified model and RLS rule: (.pbix is attached at bottom)

vjingzhanmsft_2-1740644557878.png

vjingzhanmsft_0-1740644460915.png

In Power Query Editor, DimMarket and DimSpecies still exist but not loaded to the model. Personlly I recommend maintaining DimMarket and DimSpecies tables separately. But if you don't want to have them, we can also generate distinct value lists from UserAccessList or Sales directly for transformation use. It's up to you.  

vjingzhanmsft_3-1740644651815.png

Best Regards,
Jing

Anonymous
Not applicable

Hi @Anonymous   

 

DimMarket and DimSpecies tables are not a must. The main reason I added them was because I was worried that the Market or Species in the Sales table and the UserAccessList table would be incomplete. I have DimMarket and DimSpecies tables for providing values to replace "All" string in UserAccessList table. I use some Power Query functions to do that so you don't need to list down all countries/species combinations manually. Only rows with "All" will be expanded. 

 

In addition, the DimUser table is not a must either. You can remove it and create RLS rule on UserAccessList table directly. 

 

Check my transformation steps in Power Query Editor. I don't paste them all here to save the space. Let me know if you have futher queries. 

 

Best Regards,
Jing

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.