S3 · Row-level security · about 15 min
Manager of Two Teams
hardThe Managers role filters Teams with LOOKUPVALUE on the user's email, and it works for most managers. Then m.okafor@example.com, who runs both the Riverton Rams and the Lakeside Lynx, opens the report and gets an error instead of their numbers.
Your task
Fix the Managers role so a manager of two teams sees both, a one-team manager still sees only theirs, and someone who is not in the Managers table sees nothing. Test it with Modeling > View as > Other user. Keep every relationship single direction.
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.
- T1Two-team manager, runs by team
As m.okafor@example.com in the Managers role: total runs per team. - T2Two-team manager, all games
As m.okafor@example.com in the Managers role: total number of games. - T3One-team manager
As a.lindqvist@example.com in the Managers role: total runs per team. - T4Unknown email sees nothing
As nobody@example.com, who is not in the Managers table: total runs. - 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 m.okafor@example.com. LOOKUPVALUE returns one value. How many rows in Managers have that email?
Hint 2
Instead of looking up one TeamID, get the list of every TeamID listed against the email, and keep a team if its ID is in that list.
Hint 3 (near-answer)
On Teams: Teams[TeamID] IN CALCULATETABLE( VALUES( Managers[TeamID] ), Managers[Email] = USERPRINCIPALNAME() ).
Show the editorial
Solve it first if you can: the editorial gives the answer away.
The trap
LOOKUPVALUE expects at most one match. For a manager with two rows in Managers it raises "A table of multiple values was supplied where a single value was expected", and the report fails for that manager. Swapping it for MAX or MAXX hides the error but shows only one of the two teams, which is worse because nobody notices.
The fix
Teams[TeamID] IN CALCULATETABLE( VALUES( Managers[TeamID] ), Managers[Email] = USERPRINCIPALNAME() )
Why it works
CALCULATETABLE returns every TeamID listed against the email, however many there are, and IN keeps each team whose ID is in that list. An unknown email gives an empty list, so that user sees nothing. The filter still sits on Teams, so it flows down to Games and Batting.
When one user can map to several rows, look up a list and test membership with IN, never a single-value lookup.