Forum Discussion
Row level security setup based on the column values in SQL Table
Hi aaedla Please check the below example:
I have 3 tables. User, Department and Expense. I have only relationship between department and Expense table. User table is out of the relationship.
Only Admin user from User table have can see all my reports and the tagged as leader will be able to see reports of assigned department.
My relationship:
My unfiltered report :
I have just 3 department and 4 user, 2 with Admin tag and 2 with Leader tag. See the user table:
For admin, setup just role is admin. See images below:
Check view as :
For Leader write the below dax to filter:
I have first filter user table based on Role which is Leader and then created a list of department ID crosponding to Leader tag, in my case {1,2} and checked [Department ID] of Expense table is in the list or not. If then it will filter.
Check view as:
Now go to power bi and set up as grazitti_sapna mentioned and you are done.
You need to adjust condition to filter user table based on UserName or Userprincipal name, for example :
IF (
CALCULATE (
COUNTROWS ( 'User' ),
FILTER (
'User',
'User'[Email] = USERPRINCIPALNAME() &&
'User'[Role] = "Leader"
)
) > 0,
[DepartmentID] IN
CALCULATETABLE (
VALUES ( 'User'[DepartmentID] ),
FILTER (
'User',
'User'[Role] = "Leader"
)
),
FALSE
)
Hope this helps!!
If this solved your problem, please accept it as a solution and a kudos!!
Best Regards,
Shahariar Hafiz