Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

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
[email protected]AllSwine
[email protected]Thailand

Ruminants

[email protected]MalaysiaPoultry
[email protected]ThailandAll
[email protected]JapanSwine

 

Data Set:

MarketSpeciesSales
ThailandSwine100
ThailandRuminants86
ThailandPoultry45
MalaysiaSwine12
MalaysiaRuminants57
MalaysiaPoultry46
JapanSwine31
JapanRuminants256
JapanPoultry

384

  • Anonymous's avatar
    Anonymous
    1 year ago

    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.) 

     

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

     

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

    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!

5 Replies

  • Anonymous's avatar
    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's avatar
      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.) 

       

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

       

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

      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's avatar
        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.