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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

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
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.