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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
hideakisuzuki01
Helper II
Helper II

Dynamic RLS with multiple USERPRINCIPALNAME()

Hi

I am trying to implement dynamic RLS but having trouble and it would be great if I could some help.

I have the below two tables and I have the below formula 

 

[email] = USERPRINCIPALNAME()

 

It works fine for the first two customerIDs (A and B) but it does not work for Customer IDs C and D.

It would work if I create multiple rows for C and D but that would make the table relationship many to many and produces wrong data.

How could I implement dynamic RLS in this situation ?

 

IDAmountCustomerID
1100A
2200A
3300B
4400B
5500B
6600C
7700C
8800D
9900D
101000D
CustomerIDCustomer Nameemail
AAAA111@xxxxxx.com
BBBB222@xxxxx.com
CCCC222@xxxxx.com,333@xxxxx.com
DDDD333@xxxxx.com,444@xxxxx.com

 

Below table would work but the data would be wrong since it would be many to many relationship.

 

CustomerIDCustomer Nameemail
AAAA111@xxxxxx.com
BBBB222@xxxxx.com
CCCC222@xxxxx.com
CCCC333@xxxxx.com
DDDD333@xxxxx.com
DDDD444@xxxxx.com
1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @hideakisuzuki01 

I build two tables like yours to have a test.

Data Table:

1.png

User Table (It has been transformed in Power Query editor by Split.):

2.png

Build a many to many relationship between CustomerID columns in two tables.

Then Add two Dax expression in Mange roles.

In Data table:

[CustomerID] = 
CALCULATE (
    MAX(Data[CustomerID]),
    FILTER (
        User,
        User[email] = USERPRINCIPALNAME()
            && User[CustomerID] = Data[CustomerID]
    )
)

In User table:

[email] = USERPRINCIPALNAME()

Let's use view as to see the result.

3.png

You can download the pbix file from this link: Dynamic RLS with multiple USERPRINCIPALNAME()

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

View solution in original post

3 REPLIES 3
v-rzhou-msft
Community Support
Community Support

Hi @hideakisuzuki01 

I build two tables like yours to have a test.

Data Table:

1.png

User Table (It has been transformed in Power Query editor by Split.):

2.png

Build a many to many relationship between CustomerID columns in two tables.

Then Add two Dax expression in Mange roles.

In Data table:

[CustomerID] = 
CALCULATE (
    MAX(Data[CustomerID]),
    FILTER (
        User,
        User[email] = USERPRINCIPALNAME()
            && User[CustomerID] = Data[CustomerID]
    )
)

In User table:

[email] = USERPRINCIPALNAME()

Let's use view as to see the result.

3.png

You can download the pbix file from this link: Dynamic RLS with multiple USERPRINCIPALNAME()

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

amitchandak
Super User
Super User

@hideakisuzuki01 , c is having same email ID as B ? Same for D same email ID as C.

Yes, B and C has the same email, because I want both users (222@xxxxx.com and 333@xxxxx.com) to have access to Company B and C`s data.

Does it make sense ?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors