Forum Discussion
Row Level Security based on organisation structure - multiple conditions
Hi IzBell ,
Please try the formula below:
VAR CurrentUser = USERPRINCIPALNAME()
// Read the current user’s values from the RLS table
VAR ViewAllFlag =
CALCULATE( MAX( 'RLS'[View All?] ),
FILTER( 'RLS', 'RLS'[Email] = CurrentUser )
)
VAR RLS_EmployeeID =
CALCULATE( MAX( 'RLS'[Employee ID] ),
FILTER( 'RLS', 'RLS'[Email] = CurrentUser )
)
VAR AllowedOrgUnit =
CALCULATE( MAX( 'RLS'[Org Unit] ),
FILTER( 'RLS', 'RLS'[Email] = CurrentUser )
)
VAR ExcludedOrgUnit =
CALCULATE( MAX( 'RLS'[Org Unit - Exclusion] ),
FILTER( 'RLS', 'RLS'[Email] = CurrentUser )
)
VAR AllowedTeam =
CALCULATE( MAX( 'RLS'[Team] ),
FILTER( 'RLS', 'RLS'[Email] = CurrentUser )
)
VAR ExcludedTeam =
CALCULATE( MAX( 'RLS'[Team - Exclusion] ),
FILTER( 'RLS', 'RLS'[Email] = CurrentUser )
)
VAR AllowedDepartment =
CALCULATE( MAX( 'RLS'[Department] ),
FILTER( 'RLS', 'RLS'[Email] = CurrentUser )
)
VAR ExcludedDepartment =
CALCULATE( MAX( 'RLS'[Department - Exclusion] ),
FILTER( 'RLS', 'RLS'[Email] = CurrentUser )
)
// (Similarly do for Function and Role if needed)
VAR ExcludedFunction =
CALCULATE( MAX( 'RLS'[Function - Exclusion] ),
FILTER( 'RLS', 'RLS'[Email] = CurrentUser )
)
VAR ExcludedRole =
CALCULATE( MAX( 'RLS'[Role - Exclusion] ),
FILTER( 'RLS', 'RLS'[Email] = CurrentUser )
)
// Build the allowed conditions for dimension matches.
// If an allowed value is provided then only matching rows will be visible.
// Also, if an exclusion value exists, rows with that value get filtered out.
VAR OrgUnitCondition =
( ISBLANK( AllowedOrgUnit ) || 'Data'[Org Unit] = AllowedOrgUnit )
&& ( ISBLANK( ExcludedOrgUnit ) || 'Data'[Org Unit] <> ExcludedOrgUnit )
VAR TeamCondition =
( ISBLANK( AllowedTeam ) || 'Data'[Team] = AllowedTeam )
&& ( ISBLANK( ExcludedTeam ) || 'Data'[Team] <> ExcludedTeam )
VAR DepartmentCondition =
( ISBLANK( AllowedDepartment ) || 'Data'[Department] = AllowedDepartment )
&& ( ISBLANK( ExcludedDepartment ) || 'Data'[Department] <> ExcludedDepartment )
VAR FunctionAndRoleExclusion =
( ISBLANK( ExcludedFunction ) || 'Data'[Function] <> ExcludedFunction )
&& ( ISBLANK( ExcludedRole ) || 'Data'[Role] <> ExcludedRole )
RETURN
// A row is visible if either the user is a “view all” user,
// OR if all the matching conditions are met,
// AND the Data row does not belong to the current user.
( ViewAllFlag = "Y" ||
( OrgUnitCondition &&
TeamCondition &&
DepartmentCondition &&
FunctionAndRoleExclusion )
)
&& ('Data'[Employee ID] <> RLS_EmployeeID)
Best Regards
- IzBell1 year agoFrequent Visitor
Hi Anonymous
Thank you very much for your reply.
The formula is very close, but two users are not getting the expected results.
- it picks up 3 records rather than 2.
- Expected result - it should not include Singapore.
- it picks up 2 records rather than 5.
- Expected result - it should only exclude record where DC + Result + HR + HR Manager.
Kind regards,IzBell
- v-aatheeque1 year agoCommunity Support
Hi IzBell ,
For the above scenario for [email protected]- This was happening because your email has multiple access entries in the RLS table (e.g., one for Canada and one for USA). However, the previous rule was only picking one row instead of combining them.
[email protected] seeing 2 records instead of 5
- This user had several exclusion conditions like Team, Org Unit, Role, etc. Earlier, these were getting mixed together, which caused valid rows to be hidden.
- Ensure that each exclusion rule is treated separately data is only excluded if it matches all conditions from any one exclusion row, which is the correct behavior.
Hope this helps !
If this post was helpful, please consider marking Accept as solution to assist other members in finding it more easily.
If you continue to face issues, feel free to reach out to us for further assistance!
- v-aatheeque1 year agoCommunity Support
Hi IzBell ,
We haven’t heard back from you regarding our previous response and wanted to check if your issue has been resolved.
If it has, please consider clicking “Accept Answer” and “Yes” if you found the response helpful.
If you still have any questions or need further assistance, feel free to let us know — we're happy to help!Thank you!