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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

RLS in Direct Query

Hi Guys

 

I created the below expression for RLS and it worked perfectly for my imported tables but when using the same for Direct Query it is giving me an error.

 

kindly help in sorting this as I'm stuck with this issue.

 

[CompanyId]=
CALCULATE (
MAX ( Deals[CompanyId] ),
FILTER ( Users, Users[LoginLevelName] = "Owner")
)

 

Error:

 

Himanshu_13_0-1609158484837.png

 

Regards,

Himanshu

6 REPLIES 6
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

Based on my test,the RLS rule works in direct query:

My original table is as below:

Screenshot 2020-12-30 085650.png

And my RLS rule is :

Screenshot 2020-12-30 085726.png

And you will see that it works after clicking test as a role:

Screenshot 2020-12-30 085753.png

No error returns.

But if you are having an issue,you could try to separate the rule as below:

Screenshot 2020-12-30 085818.png

Then create a measure :

_Value = CALCULATE(MAX(TEST[Value]),FILTER(ALL(TEST),'TEST'[Country]=SELECTEDVALUE(TEST[Country])))

You will also see:

Screenshot 2020-12-30 085842.png

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

aj1973
Community Champion
Community Champion

Hi @Anonymous 

Direct Query mode comes with limitations, Including using measures

https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-use-directquery

 

I recommend using the Power BI desktop feature to implement RLS

https://docs.microsoft.com/en-us/power-bi/admin/service-admin-rls

 

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Anonymous
Not applicable

It doesnt solve the issue. 

 

Is there a way I can change this expression as per the Direct query?

 

[CompanyId]=
CALCULATE (
MAX ( Deals[CompanyId] ),
FILTER ( Users, Users[LoginLevelName] = "Owner")
)

 

Regards,

Himanshu

aj1973
Community Champion
Community Champion

Nothing wrong with the measure! but CALCULATE is not allowed in RLS

Did you try to implement RLS through the desktop instead of measure? if it didn't work then you might need to change the Mode of connection to Import mode at least for the User Table. But still you will need to use the RLS of the desktop.

 

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

amitchandak
Super User
Super User

@Anonymous , check ,if this video from guyinacube can help ?

https://guyinacube.com/2016/06/07/row-level-security-for-cloud-models-and-directquery-in-power-bi/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi Amit,

 

Hope you're doing good.

 

This video doesn't help as I'm doing RLS at Desktop level and the video shows RLS functionality as Service level.

 

Regards,

Himanshu

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.