Forum Discussion

naninamu's avatar
naninamu
Helper IV
3 years ago
Solved

RLS with conditional tables

Hello - was helping someone could help me as I attempt to implement RLS on a model I've inherited.   Simply put, the User is in a table with their ID and another column which specifics which table ...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi naninamu ,

    Please try to create a role with below dax formula:

    [Area] =
    VAR _id =
        USERPRINCIPALNAME ()
    VAR a =
        CALCULATE ( MAX ( 'User'[Table] ), CONTAINSSTRING ( 'User'[ID], _id ) )
    VAR b =
        CALCULATE ( MAX ( 'Table A'[Area] ), CONTAINSSTRING ( 'Table A'[ID], _id ) )
    VAR c =
        CALCULATE ( MAX ( 'Table B'[Area] ), CONTAINSSTRING ( 'Table B'[ID], _id ) )
    VAR val =
        SWITCH ( a, "A", b, "B", c )
    RETURN
        val
    

    add a table visual with Table fields:

     

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.