Forum Discussion
Dynamic Row Level Security Based on Contract
Hi,
I am trying to set up Dynamic Row Level Security for a large dashboard where each contract should only see their reporting metrcis. There are multiple people in a contract so I know it needs to be based on email but everyone should see their own contract only.
I have set up a Users Table, Employee Table and obvioulsly data.
I cannot seem to get the synxtax right so that I could view each dataset based upon the contract selected only.
Can anyone help? I know I need two tables that I have to use the Userprincipalname function but I am struggling with the rest of this.
Sales- Desired
| Name | Email Address | Hire Date | Contract | EmployeeID | UNIQUE CONTRACT AND NAME | Sales |
| A | [email protected] | 13-Jun-18 | ABC | 1 | A-ABC | 10 |
| E | [email protected] | 29-Jul-19 | ABC | 5 | E-ABC | 125 |
| F | [email protected] | 16-Dec-19 | ABC | 6 | F-ABC | 50 |
| K | [email protected] | 23-Oct-19 | ABC | 11 | K-ABC | 75 |
Employee Table
| Name | EmailAddress | Hire Date | EmployeeID | Contract | Unique ID |
| A | [email protected] | 14-Sep-98 | 1 | ABC | A-ABC |
| B | [email protected] | 16-Nov-98 | 2 | CBD | B-CBD |
| C | [email protected] | 3-Oct-14 | 3 | DEF | C-DEF |
| D | [email protected] | 27-Nov-17 | 4 | GHI | D-GHI |
| E | [email protected] | 9-Mar-18 | 5 | ABC | E-ABC |
| F | [email protected] | 29-Jun-01 | 6 | ABC | F-ABC |
Users Table
| Name | Email Address | Hire Date | Contract | EmployeeID | UNIQUE CONTRACT AND NAME |
| A | [email protected] | 13-Jun-18 | ABC | 1 | A-ABC |
| B | [email protected] | 18-Jun-18 | CBD | 2 | B-CBD |
| C | [email protected] | 25-Jan-21 | DEF | 3 | C-DEF |
| D | [email protected] | 25-Oct-17 | GHI | 4 | D-GHI |
| E | [email protected] | 29-Jul-19 | ABC | 5 | E-ABC |
| F | [email protected] | 16-Dec-19 | ABC | 6 | F-ABC |
7 Replies
- lbendlinSuper User
yes, use USERPRINCIPALNAME and apply the RLS on the outermost dimension table of your data model.
What's the reason for having a user table and an employee table?
- AnonymousNot applicable
I don't think I need both tables either but I had seen other examples where that worked. I can never get the userprincipalname to work.
Are you really just using one filter on the email? Do you have an example? Thanks!
- lbendlinSuper User
The usual pitfalls with RLS are
- you have users with workspace roles above viewer => RLS is ineffective
- your data model links are pointing towards the RLS table => ditto.
Other than that USERPRINCIPALNAME works "fine".
Personal note: Do you really need RLS? Is your data sensitive? Because if not then all you are achieving is to irritate your users.
- AnonymousNot applicable
Data is super sensitive.
In this case, how you you set up the formula in the manage roles?
- lbendlinSuper User
In the Employees table:
[Email Address]=USERPRINCIPALNAME()
- AnonymousNot applicable
Right but I need everyone from the contract to be able to see it with many emails being associated with the same contract. I guess i am missing something.