Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Ben1981
Helper III
Helper III

RLS based on CONTAINSSTRING?

Hi,

Is there a way with RLS to filter a column based on if a value is contained within a string? 


I have two tables setup, HR People and HR Hierarchy, no connected to each other but can be via Person ID.

The HR people table has all employee IDs, Name and Email address and then the Hierarchy has PersonID and Path (path being a string that contains all the person IDs above that person, seperated by a deilimiter)


I have tried this bit of code but so far it has not worked as I hoped..

VAR
GetUserID =
MAXX(
FILTER('Dim HR People',
'Dim HR People'[Email] = USERPRINCIPALNAME() ),
'Dim HR People'[ID Key] )
RETURN
[Path] = CONTAINSSTRING('_Dim Hierarchy'[Path],GetUserID)

Anyone help would be appreiciated.

1 ACCEPTED SOLUTION
pankajnamekar25
Super User
Super User

Hello @Ben1981 

 

try with this DAX code


In your RLS role definition (for table 'Dim HR Hierarchy')

VAR _UserID =
MAXX(
FILTER('Dim HR People', 'Dim HR People'[Email] = USERPRINCIPALNAME()),
'Dim HR People'[ID Key]
)
RETURN
CONTAINSSTRING('Dim HR Hierarchy'[Path], _UserID)

 


If my response helped you, please consider clicking
Accept as Solution and giving it a Like 👍 – it helps others in the community too.


Thanks,


Connect with me on:

LinkedIn

 

View solution in original post

6 REPLIES 6
v-pnaroju-msft
Community Support
Community Support

Hi Ben1981,

We kindly request you to provide sample data that clearly demonstrates your issue or query in a structured format (not as an image) to help us understand and resolve the matter. Please ensure that the data is relevant, free from any sensitive information, and directly related to the issue. Additionally, please share the expected outcome based on the given example.

Thank you.




v-pnaroju-msft
Community Support
Community Support

Hi Ben1981,

Please share some sample data that shows your problem or question clearly in a simple and organized way (not as an image). This will help us understand and solve the issue better. Make sure the data is relevant, does not have any sensitive information, and is related to your problem. Also, please tell us what result you expect from this example.

Thank you.

v-pnaroju-msft
Community Support
Community Support

Thankyou, @Ahmedx and @pankajnamekar25 for your response.

Hi Ben1981,

We appreciate your question on the Microsoft Fabric Community Forum.

We kindly request you to provide sample data that clearly demonstrates your issue or query in a structured format (not as an image) to help us understand and resolve the matter. Please ensure that the data is relevant, free from any sensitive information, and directly related to the issue. Additionally, please share the expected outcome based on the given example.

Thank you.

pankajnamekar25
Super User
Super User

Hello @Ben1981 

 

try with this DAX code


In your RLS role definition (for table 'Dim HR Hierarchy')

VAR _UserID =
MAXX(
FILTER('Dim HR People', 'Dim HR People'[Email] = USERPRINCIPALNAME()),
'Dim HR People'[ID Key]
)
RETURN
CONTAINSSTRING('Dim HR Hierarchy'[Path], _UserID)

 


If my response helped you, please consider clicking
Accept as Solution and giving it a Like 👍 – it helps others in the community too.


Thanks,


Connect with me on:

LinkedIn

 

Hi, so this seems to work when I view role as me but if I try view as other and put in the login details for another user then it doens't work. 

So not sure if it's because of the view as other isn't working right because of the details I've inputted or if the code above does not work?

Ahmedx
Super User
Super User

study this

VAR
GetUserID =
MAXX(
FILTER('Dim HR People',
'Dim HR People'[Email] = USERPRINCIPALNAME() ),
'Dim HR People'[ID Key] )
RETURN

CONTAINS('_Dim Hierarchy,'_Dim Hierarchy'[Path],GetUserID)

https://radacad.com/dynamic-row-level-security-with-organizational-hierarchy-power-bi

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.