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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
ptmuldoon
Resolver I
Resolver I

CONTAINSSTRING in Security Roles not allowed?

I am working/learning to convert a pbix file and data model into the PB service, and having an issue with Permissions Role I have in my pbix file failing on the service.

 

I have this in Role in my pbix file which uses ContainsString.  

 

CONTAINSSTRING(
    MAXX(
        FILTER(
            Users,
            Users[Email]=USERPRINCIPALNAME()
        ),
        Users[Regions]
    ),
    [Region]
)

 

But the code above gives an error message when I copy it into the model/role on the service of:

 

Function 'CONTAINSSTRING' is not allowed as part of the row level security expression on DirectQuery models. 

 

Can anyone help how I need to modify that code to work?  I've been reading about trying with LIKE and INSTR, but have not gotten this working yet.

 

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ptmuldoon ,

 

As far as I know, the CONTAINSSTRING function is really not supported in row-level security (RLS) role queries. This may limit your flexibility in defining roles. I recommend that you complete the task of obtaining the column maximum value and determining whether the value contains the maximum value in the report. For example, create measure.

The security role:

=USERPRINCIPALNAME()

Create measure in report.

Measure = VAR maxregion = CALCULATE(MAX('Users'[Regions]),ALL('Users'))
RETURN IF(FIND(maxregion, MAX('Users'[Regions]), 1, 0) > 0, "Found", "Not Found")

Filter measure equals "Found" and lock the filter.

vmengmlimsft_0-1733298884850.png

 

 

 

 

 

Best regards,

Mengmeng Li

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @ptmuldoon ,

 

As far as I know, the CONTAINSSTRING function is really not supported in row-level security (RLS) role queries. This may limit your flexibility in defining roles. I recommend that you complete the task of obtaining the column maximum value and determining whether the value contains the maximum value in the report. For example, create measure.

The security role:

=USERPRINCIPALNAME()

Create measure in report.

Measure = VAR maxregion = CALCULATE(MAX('Users'[Regions]),ALL('Users'))
RETURN IF(FIND(maxregion, MAX('Users'[Regions]), 1, 0) > 0, "Found", "Not Found")

Filter measure equals "Found" and lock the filter.

vmengmlimsft_0-1733298884850.png

 

 

 

 

 

Best regards,

Mengmeng Li

 

Thanks,

I'll try and give that a shot.  But I think that means I would need to set that Measure and Filter on every report page correct?    Or do you think that will also work within the RLS and adding to the Security Role?

Anonymous
Not applicable

Hi @ptmuldoon ,

 

I think so. Because security role queries in direct quer mode are not supported for many DAX functions, this is due to query performance considerations at the beginning of the design. It is reassuring that RLS filtering always takes precedence over DAX queries in reports. 

 

 

Best regards,

Mengmeng Li

ptmuldoon
Resolver I
Resolver I

I've been experimenting and while I still haven't figure this out yet, I'm not sure if this is an issue with CONTAINSSTRING or not.

 

In the below code, If I hardcode a value, it appears to work.  But when I try to use the returned result of variable, I still get the same error?

Var UserRegions = 
        var filteredTable = FILTER(Users, Users[Email]=USERPRINCIPALNAME())
        return SELECTCOLUMNS(filteredTable,"Region", Users[Regions])

RETURN
//CONTAINSSTRING([Region], "Test")
CONTAINSSTRING([Region], UserRegions)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

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.