Forum Discussion

MellishT's avatar
MellishT
Regular Visitor
11 months ago
Solved

Tricky Row Level Security Problem

Hi! I am developing in Power BI and I came upon a tricky RLS situation that I can't quite figure out. Thank you for taking the time to read this!   My data model consists of many different datasets...
  • Ilgar_Zarbali's avatar
    11 months ago

    If you need to manage row-level security (RLS) so that teachers can see:

    • All current students in their school, and
    • All assessments conducted at their school (even for students who have left),
      you can handle this cleanly by using two roles and combining their permissions.

     

    Create two roles and assign teachers to both.

     

    Role A – CurrentStudents
    Filter the Demographics table by the teacher’s school:

     

    Demographics[School] IN
    CALCULATETABLE(VALUES(Users[School]), Users[UPN] = USERPRINCIPALNAME())

     

    This ensures they only see data for students currently in their school.

     

    Role B – AssessmentsAtMySchool
    Filter the Assessments table by the school column:

     

    Assessments[School] IN
    CALCULATETABLE(VALUES(Users[School]), Users[UPN] = USERPRINCIPALNAME())

     

    For all other tables in this role, set the filter to:

     

    FALSE()

     

    This prevents exposing other data while still allowing access to all assessments from that school.

     

    How it works

    • Power BI unions the results of both roles.
    • Teachers see all data for current students plus all assessments from their school — even for students no longer there.