S2 · Row-level security · about 15 min
Managers See Their Team
mediumEach team manager should see only their own team. A colleague added a Managers table (one row per manager email and TeamID) and a role named Managers that filters Managers[Email] = USERPRINCIPALNAME(). In testing, every manager sees the whole league.
Your task
Fix the Managers role so a manager sees only the team listed against their email, and someone who is not in the Managers table sees nothing. Test it with Modeling > View as > Other user. Keep every relationship single direction. Each manager in these tests runs one team.
What the grader checks
You see the situations, not the expected numbers. The expected values are computed live from your file and the source data.
- T1One manager, runs by team
As a.lindqvist@example.com in the Managers role: total runs per team. - T2Another manager, games by team
As r.nakamura@example.com in the Managers role: number of games per team. - T3Unknown email sees nothing
As nobody@example.com, who is not in the Managers table: total runs. - T4Team list
As s.delgado@example.com in the Managers role: how many teams a Team slicer would list. - M1No bidirectional filters
Every relationship in the model filters in one direction only.
Stuck?
Open one hint at a time.
Hint 1
Use View as > Other user with a.lindqvist@example.com and the Managers role. The Managers table shrinks to one row, but Games and Batting don't. Which way does the arrow between Managers and Teams point?
Hint 2
Filters travel from Teams to Managers, never back. A filter on Managers hides manager rows and nothing else. The filter has to sit on Teams, and look up the user's team from there.
Hint 3 (near-answer)
On Teams: Teams[TeamID] = LOOKUPVALUE( Managers[TeamID], Managers[Email], USERPRINCIPALNAME() ). LOOKUPVALUE needs no relationship to find the value.
Show the editorial
Solve it first if you can: the editorial gives the answer away.
The trap
The filter sits on Managers, which is the many side of Managers to Teams. Filters only travel from the one side to the many side, so it hides rows in Managers and nothing else: every manager, and anyone not in the table at all, sees the whole league. Making the relationship bidirectional looks like a fix, but it changes how every other filter behaves, and RLS needs a separate security setting to cross it.
The fix
Filter Teams with the user's team: Teams[TeamID] = LOOKUPVALUE( Managers[TeamID], Managers[Email], USERPRINCIPALNAME() ).
Why it works
LOOKUPVALUE finds the logged-in user's TeamID in Managers without using any relationship. The filter then sits on Teams, at the top of the chain, so it flows down to Games and Batting like a slicer. For an email that isn't in Managers, LOOKUPVALUE returns blank, which matches no team, so that user sees nothing.
A security filter only travels the way the arrows point. Put it on the table whose filter reaches the data, and look the user up from there.