Forum Discussion

raju8004212's avatar
raju8004212
Frequent Visitor
1 year ago
Solved

Dynamic Row level security

Hi Anonymous 

dynamic swithcing of rls is  based on slicer selection
rls logic working with out selection if we  include slicer selection  in rls its not wrking 

my model is like bu_org ,snap connected to combof want to switch rls based on selection
before selection 

WC_BU_ORG_DH[PU_VALUE] IN 
    CALCULATETABLE(
        VALUES(Union_table[ANCESTOR_KEY]),
        FILTER(
            Union_table,
            UPPER(Union_table[EMAIL_ADDRESS]) = UPPER(USERPRINCIPALNAME())
        )
    )

 rls logic on snap_d_:

WC_EMPLOYEE_snap_D[ANCESTOR_KEY] IN 
    CALCULATETABLE(
        VALUES(Union_table[ANCESTOR_KEY]),
        FILTER(
            Union_table,
            UPPER(Union_table[EMAIL_ADDRESS]) = UPPER(USERPRINCIPALNAME())
        )
    )

 

if use above  logics independently those are working now im making like 
created disconnected table with type hr and pu  and making my logics like

updated with slicer selection_bu_org_dh rls dynamic
IF (
SELECTEDVALUE(Union_table[Type]) = "PU",
WC_BU_ORG_DH[PU_VALUE] IN
CALCULATETABLE(
VALUES(Union_table[ANCESTOR_KEY]),
FILTER(
Union_table,
UPPER(Union_table[EMAIL_ADDRESS]) = UPPER(USERPRINCIPALNAME())
)
),TRUE()
)

updated rls for snap_d:

IF (
SELECTEDVALUE(Union_table[Type]) = "HR",
WC_EMPLOYEE_snap_D[ANCESTOR_KEY] IN
CALCULATETABLE(
VALUES(Union_table[ANCESTOR_KEY]),
FILTER(
Union_table,
UPPER(Union_table[EMAIL_ADDRESS]) = UPPER(USERPRINCIPALNAME())
)

),
TRUE()
)

now the updated logic needs to work like if we select pu the pu logic needs to apply rls else it shows all values like no filter vice versa for sanp_d table

please hep me to work this 

thanks in advance

  • v-sshirivolu's avatar
    v-sshirivolu
    1 year ago

    Hi raju8004212 ,
    To clarify it isn’t possible to pass slicer values or variables into RLS. Power BI always applies
    RLS first (based on user identity), and only afterwards slicers/filters.

    That means a “toggle RLS by slicer” design isn’t supported. The only supported approaches are:

    Dynamic RLS using USERPRINCIPALNAME()  and a security mapping table.

    Report-level toggles (disconnected slicer + measures/filters) to switch between PU/HR views within the user’s authorized data.

    Separate roles/reports if different security contexts are mandatory.

    So the workarounds I shared earlier will help you simulate the toggle experience, but the true RLS logic can’t be driven by slicers.

18 Replies

  • Please include, in a usable format, not an image, a small set of rows for each of the tables involved in your request and show the data model in a picture, so that we can import the tables in Power BI and reproduce the data model. The subset of rows you provide, even is just a subset of the original tables, must cover your issue or question completely. Do not include sensitive information and do not include anything that is unrelated to the issue or question. Please show the expected outcome based on the sample data you provided and make sure, in case you show a Power BI visual, to clarify the columns used in the grouping sections of the visual.

     

    Need help uploading data? click here

     

    Want faster answers? click here

    • raju8004212's avatar
      raju8004212
      Frequent Visitor

      Hi FBergamaschi 

       

      It's just like I have a mechanism where a connected c and b connected to c

       

      Here a is dimension and b is dimension c is fact

      My scenario like I have rls on both and b 

      But I need slicer selection to select which rls I need to choose

      Like slicer shows a 

      Then all visuals will be filter for users level access to table a

      If slicer shows b

      Then visuals will be filtered to rls level access to table b 

      It's like switch the rls and enable the user to which rls data they want to see

    • raju8004212's avatar
      raju8004212
      Frequent Visitor

      Hi FBergamaschi ,

       

      sample data for table --a
      sample data for table--b


      sample data for fact table


      data model is like

      sample visual like below slicer one came from table a slicer 2 came from table b metrics from table c(fact)

       

      now im creating 2 security roles to restrict table a data and table b data based on rls filter

      1.who ever logged their pu data only they can see
      2.who ever logged their reportee data only they can see
      we want to enable the role switch mechanism in report to which role they want see data in report like hr or pu using toggle or slicer

  • Hi raju8004212 

    How about doing this with a disconnected table instead:

    Type
    PU
    HR


    Now you can use this as the slicer

    For bu_org:

    IF (
        SELECTEDVALUE('RLS_Type_Switch'[Type]) = "PU",
        WC_BU_ORG_DH[PU_VALUE] IN 
            CALCULATETABLE(
                VALUES(Union_table[ANCESTOR_KEY]),
                FILTER(
                    Union_table,
                    UPPER(Union_table[EMAIL_ADDRESS]) = UPPER(USERPRINCIPALNAME())
                )
            ),
        TRUE()
    )

     
    For Snap_D:

    IF (
        SELECTEDVALUE('RLS_Type_Switch'[Type]) = "HR",
        WC_EMPLOYEE_snap_D[ANCESTOR_KEY] IN 
            CALCULATETABLE(
                VALUES(Union_table[ANCESTOR_KEY]),
                FILTER(
                    Union_table,
                    UPPER(Union_table[EMAIL_ADDRESS]) = UPPER(USERPRINCIPALNAME())
                )
            ),
        TRUE()
    )
    • raju8004212's avatar
      raju8004212
      Frequent Visitor

      Hi MohamedFowzan1 

       

      I'm not able to pass slicer values into rls whether it's a disconnected/ same table that's main problem I tried that as well it's not  working thanks for checking I'm really looking for some help here to identify a way to make it working.

       

       

      • MohamedFowzan1's avatar
        MohamedFowzan1
        Super User

        I did some digging, and it looks like there’s no direct way to have a slicer function like that in conjunction with RLS. The only possible approach would be a workaround without using any RLS, but that would be purely for user experience and not enforce any real security.

        In terms of RLS, the proper method is still to define distinct roles and apply the appropriate filters based on user condition essentially assigning users to the roles that match their access requirements.

  • v-sshirivolu's avatar
    v-sshirivolu
    Community Support

    Hi raju8004212 ,
    Thank you for reaching out to Microsoft Fabric Community Forum.

    Union_table: stores role-to-user mapping

    EMAIL_ADDRESS | TYPE | ANCESTOR_KEY
    [email protected] | PU | 1001
    [email protected] | HR | 3001
    [email protected] | PU | 2002

    Create Single Role with Conditional RLS Logic - Dynamic_RLS 

    Apply Filter to
    WC_BU_ORG_DH
    WC_BU_ORG_DH[PU_VALUE] IN
    SELECTCOLUMNS(
    FILTER(
    Union_table,
    UPPER(Union_table[EMAIL_ADDRESS]) = UPPER(USERPRINCIPALNAME())
    && Union_table[TYPE] = "PU"
    ),
    "Key", Union_table[ANCESTOR_KEY]
    )

    Apply Filter to WC_EMPLOYEE_snap_D

    WC_EMPLOYEE_snap_D[ANCESTOR_KEY] IN
    SELECTCOLUMNS(
    FILTER(
    Union_table,
    UPPER(Union_table[EMAIL_ADDRESS]) = UPPER(USERPRINCIPALNAME())
    && Union_table[TYPE] = "HR"
    ),
    "Key", Union_table[ANCESTOR_KEY]
    )

     

    Test the RLS

    View as Roles - 
    Select "Other User" and enter an email address such as [email protected]. Test:

    In WC_BU_ORG_DH, you should only see rows where PU_VALUE is 1001.

    In WC_EMPLOYEE_snap_D, only rows with ANCESTOR_KEY equal to 3001 should be visible.

    Please find the attached .pbix file for your reference

    Regards,

    Sreeteja.

     

    • raju8004212's avatar
      raju8004212
      Frequent Visitor

      Hi v-sshirivolu 

      sreeteja thanks for your response , i need to select which rls data i want to see using toggle mechanism is it possible to pass variable to rls filter

      • v-sshirivolu's avatar
        v-sshirivolu
        Community Support

        Hi raju8004212 ,
        Try These Steps - 
        Employee Table
        Employee_Name | PU_ID | HR_ID
        John | 3001 | 1001
        Steve | 1001 | 2002

        User Table
        Email | UserID
        [email protected] | 1001

        Create Disconnected Table
        User_Role =
        DATATABLE(
        "TYPE", STRING,
        {
        {"HR"},
        {"PU"}
        }
        )

        Add Slicer to Report

        Add User_Role[TYPE] as a slicer for role toggle

        Apply RLS on Employee Table

        VAR selectedRole = SELECTEDVALUE('User_Role'[TYPE])

        RETURN
        SWITCH(
        TRUE(),
        selectedRole = "HR", Employee[HR_ID] = LOOKUPVALUE(User[UserID], User[Email], USERPRINCIPALNAME()),
        selectedRole = "PU", Employee[PU_ID] = LOOKUPVALUE(User[UserID], User[Email], USERPRINCIPALNAME()),
        TRUE() // fallback - show nothing or all

        -----  This RLS rule changes based on the slicer selection.

        Enable "View As Roles" for Testing

        Navigate to Modeling > Manage Roles.

        Apply the RLS to the Employee table using the provided expression.

        Select View As Roles and choose [email protected].

        Now test by selecting HR or PU from the slicer.
        You’ll see results change based on selected role

        Please find the attached .pbix file for your reference.

        Regards,
        Sreeteja.

         

         



  • Shahid12523's avatar
    Shahid12523
    Community Champion

    True RLS → Merge PU & HR into one mapping table and write one RLS filter based on USERPRINCIPALNAME().

    Report-level workaround → Skip RLS, use a measure filter with slicer to simulate security.

    For real security → use option 1. 

  • Mo_d2's avatar
    Mo_d2
    Regular Visitor

    Research Assistance: Expert Survey on Visual Analytics Security and RLS Challenges (12 minutes)

    Greetings to our valued Power BI experts,

    I am [Mohamed Fawaz Ismail], and I am conducting a specialized study on "Visual Analytics Security" (Secure Visual Analytics). The study aims to identify the actual gaps and risks that developers and analysts face when dealing with sensitive data within dashboards (particularly in relation to RLS, encryption, and Access Control).

    Your practical experience in designing and securing dashboards using Power BI is the foundation for the success of this study. Your opinion on questions related to:

    Applying the Least Privilege Access principle.

    Dealing with accidental data leaks.

    The importance of auditing and monitoring (Logging & Auditing).

    ...It will help us formulate better security standards for the community.

    Duration: only about 12 minutes.

    Survey link: [https://docs.google.com/forms/d/e/1FAIpQLScUNJwYADW3zyv8HcX4Js8xsLClet4NyogKoYHwanJ4kbY0ww/viewform?usp=header]

    Please take a few minutes to participate. I would be happy to share a summary of the results with you later.

    Thank you very much for your time and cooperation.

    [Mohamed Fawaz Ismail]