Forum Discussion
RLS if-statement on USERPRINCIPALNAME
- 6 years ago
Hi Anonymous ,
In Manage roles, you can create new roles and try this DAX pression to solve your problem:
IF (
CALCULATE (
COUNTROWS ( 'Table' ),
FILTER ( 'Table', 'Table'[email] = USERPRINCIPALNAME () && [IsTeamlead] )
) > 0,
[Country]
= CALCULATE (
MAX ( 'Table'[Country] ),
FILTER ( 'Table', 'Table'[email] = USERPRINCIPALNAME () )
),
[email] = USERPRINCIPALNAME ()
)
When you use View as roles, you will get the following result:
Here is the demo , please try it:
Best Regards,
Yingjie Li
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Everything is possible in DAX 🙂 My guess for the RLS expression is:
'Table'[email] = USERPRINCIPALNAME() || COUNTROWS(FILTER(ALL('Table'); 'Table'[country] = EARLIER('Table'[country]) && 'Table'[email] = USERPRINCIPALNAME() && 'Table'[isteamlead]=TRUE())) > 0
- Anonymous6 years agoNot applicable
Thank you for your suggestion.
Every row (employee) has [email]. Your solution is a type Option A || Option B. Will Option B ever be evaluated if Option A is true?
- Anonymous6 years agoNot applicable
The statement will evaluate once for each row in the table. But if the first part evaluates to TRUE the second part is not evaluated for that row (since all users should have access to the row that contains their own email, right?).
- Anonymous6 years agoNot applicable
I tried your code, and it was as I expected. The first statement will evaluate true, since whenever someone logs in with the USERPRINCIPALNAME(), it will match a row. I believe the second part is never evaluated.