Forum Discussion

hideakisuzuki01's avatar
6 years ago
Solved

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
AAAA[email protected]
BBBB[email protected]
CCCC[email protected],[email protected]
DDDD[email protected],[email protected]

 

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

 

CustomerIDCustomer Nameemail
AAAA[email protected]
BBBB[email protected]
CCCC[email protected]
CCCC[email protected]
DDDD[email protected]
DDDD[email protected]
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi hideakisuzuki01 

    I build two tables like yours to have a test.

    Data Table:

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

    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.

    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. 

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi hideakisuzuki01 

    I build two tables like yours to have a test.

    Data Table:

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

    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.

    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.