Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi everyone,
I need to create a new role in Manage Roles to set up a row level security according to our hierarchy. I tried to use Pathcontains in the dax but still can't get the code working correctly. Appreciated if anyone can point me the right direction.
Here is my sample data:
Employee Name | Hierarchy | |
Tom Gland | Tom.Gland@example.com | /Tom Gland |
Lily Wy | Lily.Wy@example.com | /Tom Gland/Lily Wy |
Incy Wincy | Incy.Wincy@example.com | /Tom Gland/Lily Wy/Incy Wincy |
Kent Ford | Kent.Ford@example.com | /Tom Gland/Lily Wy/Incy Wincy/Kent Ford |
Russell Barrow | Russell.Barrow@example.com | /Tom Gland/Lily Wy/Incy Wincy/Kent Ford/Russell Barrow |
Mary Lance | Mary.Lance@example.com | /Tom Gland/Lily Wy/Incy Wincy/Kent Ford/Russell Barrow/Mary Lance |
Beatrix Tong | Beatrix.Tong@example.com | /Tom Gland/Lily Wy/Incy Wincy/Kent Ford/Russell Barrow/Mary Lance/Beatrix Tong |
Basically when employees login using their email in PowerBI, they should be able to see every employee reporting to them, directly and indirectly. For example, Kent Ford should see himself, Russell Barrow, Mary Lance, and Beatrix Tong in the dataset when he logs in.
This is my first DAX, it only returns the employee's record themselves, for example for Kend Ford, only the row with his name was visible to him when he logged in:
This is my second dax, but it returns nothing:
VAR EmployeeName = LOOKUPVALUE(Employee[Employee Name], Employee[Email], USERPRINCIPALNAME())
RETURN
PATHCONTAINS(Employee[Hierarchy], EmployeeName)
Solved! Go to Solution.
Thank you, the data comes as forward slash so I converted it to the Pipe symbol, the the following DAX works!
VAR EmployeeName = LOOKUPVALUE(Employee[Employee Name], Employee[Email], USERPRINCIPALNAME())
RETURN
PATHCONTAINS(Employee[Hierarchy], EmployeeName)
Use the Pipe symbol, not the forward slash. Use the email address in the hierarchy, not the name.
Then all you need is
Thank you, the data comes as forward slash so I converted it to the Pipe symbol, the the following DAX works!
VAR EmployeeName = LOOKUPVALUE(Employee[Employee Name], Employee[Email], USERPRINCIPALNAME())
RETURN
PATHCONTAINS(Employee[Hierarchy], EmployeeName)
User | Count |
---|---|
25 | |
10 | |
7 | |
6 | |
6 |
User | Count |
---|---|
30 | |
11 | |
11 | |
9 | |
7 |