cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Larstc Regular Visitor
Regular Visitor

Dynamic RLS with USERPrincipalName

hi guys

 

I am having some trouble with getting Dynamic RLS to work. 

 

I have created a table with all Usernames that I have related to a table with usernames and costcenters. This table is then related to the Dim Costcentertable, which is related to the fact tables. 

 

datamodel.PNG

 

 

 

I have with some borrowing from Radacad put in a second dimension (SeeALL) which I use to overwrite the PrincipalName filter for some individuals who should see all cost centers.

In the RLS filter I have the following DAX code:

If(
MaxX(
Filter(
Users,
'Users'[Username]=USERPRINCIPALNAME())
,'Users'[SeeAll])=0,
max('Users'[Username])=USERPRINCIPALNAME(),
1=1
)

 

The main problem is that it is not working, users on the User list can't get access to see anything in the app.

 

Furtermore the testing in the desktop is not really working either. It seems to only acknowledge myself as a User and everybody else can see everything when I enter their username in "view as roles" function:

 

use as roles.PNG 

 

so why is the testing giving another result (see everything = no filter) than the app in the service (no access, see belowSmiley Happy

 

error report.jpg

I have already tried to skip the above DAX code and just write:

 

Users[Username] = Userprincipalname() This gives me the same result.. which I find quite odd.

 

I have also been through a number of articles about dynamic RLS and also came across the following:

https://angryanalyticsblog.azurewebsites.net/index.php/2016/12/27/dynamic-rls-via-hierarchy-in-power...

In this article a model is available. When I use that model I still can't get the testing to work.. no matter what user I filter in "view as role" it is not filtering anything.

 

What am I doing wrong? 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Larstc Regular Visitor
Regular Visitor

Re: Dynamic RLS with USERPrincipalName

I found the solution myself. I had two problems in the above. The Dax formula; I needed to take the MAX function out, so that it is now: 

If(
MaxX(
Filter(
Users,
'Users'[Username]=USERPRINCIPALNAME())
,'Users'[SeeAll])=0,
'Users'[Username]=USERPRINCIPALNAME(),
1=1
)

Furthermore I found out that to check it in Desktop I needed to both check "Users" and "Other user"

 

Generally I find it a little frustrating that the documentation on RLS is mainly outdated and still explaining how to assign user on the web service. e.g.: https://docs.microsoft.com/da-dk/power-bi/service-admin-rls

 

..Anyhow.. it works now :-)

 

3 REPLIES 3
Highlighted
Larstc Regular Visitor
Regular Visitor

Re: Dynamic RLS with USERPrincipalName

Anybody? 

Larstc Regular Visitor
Regular Visitor

Re: Dynamic RLS with USERPrincipalName

I found the solution myself. I had two problems in the above. The Dax formula; I needed to take the MAX function out, so that it is now: 

If(
MaxX(
Filter(
Users,
'Users'[Username]=USERPRINCIPALNAME())
,'Users'[SeeAll])=0,
'Users'[Username]=USERPRINCIPALNAME(),
1=1
)

Furthermore I found out that to check it in Desktop I needed to both check "Users" and "Other user"

 

Generally I find it a little frustrating that the documentation on RLS is mainly outdated and still explaining how to assign user on the web service. e.g.: https://docs.microsoft.com/da-dk/power-bi/service-admin-rls

 

..Anyhow.. it works now :-)

 

BeanJunkie Frequent Visitor
Frequent Visitor

Re: Dynamic RLS with USERPrincipalName

I had this problem too. It turns out that I had my SeeAll column with 1's and 0's as a text field and since the DAX expression does not allow comparing Text value with Integer values it gives the error. Changing the SeeAll column to type Integer solved my problem.

Helpful resources

Announcements
Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

Virtual Launch Event

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Users Online
Currently online: 286 members 2,727 guests
Please welcome our newest community members: