Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

RLS if-statement on USERPRINCIPALNAME

Hi!

 

In my table of employees, the columns are [email], [IsTeamlead] and [country]

 

If a non-teamlead employee logs in, RLS should be [email] = USERPRINCIPALNAME (only see information about himself).

If a teamlead employee logs in, d, he should see all employees in England,  [country] = "England"

 

Is this if-statement possible in DAX?

 

  • Hi Anonymous ,

    In Manage roles, you can create new roles and try this DAX pression to solve your problem:

     

    IF (

        CALCULATE (

            COUNTROWS ( 'Table' ),

            FILTER ( 'Table', 'Table'[email] = USERPRINCIPALNAME () && [IsTeamlead] )

        ) > 0,

        [Country]

            = CALCULATE (

                MAX ( 'Table'[Country] ),

                FILTER ( 'Table', 'Table'[email] = USERPRINCIPALNAME () )

            ),

        [email] = USERPRINCIPALNAME ()

    )

     

    When you use View as roles, you will get the following result:

     

     

     

    Here is the demo , please try it:

    PBIX 

     

    Best Regards,

    Yingjie Li

     

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

8 Replies