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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Dynamic RLS

Hi,

Say like 2 tables.

1 is fact with unique accounts and its transactions.

2 is accountid and email ids.

 

an account can be shared with multiple users, so table 2 will have many records.

 

For an instance, 

Table 1:

Account ID   

1

2

3

 

Table 2:

Accountid         EmailId

1                        J@gmail.com

1                       B@gmail.com

2                       c@gmail.com

 

Like this.

 

so now i want to fapply RLS based on user login.

 

If J login he should see his accounts, if B login he should see his accounts etc..

 

i tried few measures like this but not working.

ConcatenateLookupEmail =
DISTINCT(SELECTCOLUMNS(
FILTER(Table,
Table1[AccountId] =
LOOKUPVALUE(
'Table2'[Accountid],
'Tbale2'[Email],
USERPRINCIPALNAME()
)
),
"Accountid",
Table1[AccountId])
)
CalTable = CALCULATETABLE(
VALUES(Table1[AccountId]),
'Table2'[Email] = [uname],
CROSSFILTER(Table1[AccountId],'Tbale2'[Accountid],Both))
 
 
2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

Let the data model do the work.  Link the tables, make sure the filter direction is pointing from accounts to transactions, and put the RLS on the accounts table with a simple formula:

 

[Emailid]=USERPRINCIPALNAME()

View solution in original post

Hi @Anonymous ,

 

it is as easy as described by @lbendlin 

You can find my example PBIX attached.

RLS1.png

RLS2.png

RLS3.png

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


View solution in original post

12 REPLIES 12
harshnathani
Community Champion
Community Champion

Anonymous
Not applicable

Hi Harsh, i tried thise radcad blogs, my scenario is not suited however as you see above measures with filter condition, i tried similar to those blogs. 

lbendlin
Super User
Super User

Let the data model do the work.  Link the tables, make sure the filter direction is pointing from accounts to transactions, and put the RLS on the accounts table with a simple formula:

 

[Emailid]=USERPRINCIPALNAME()

Anonymous
Not applicable

There is no emailid field in accounta table, that is soo simple RLS, that doesn't work here.

 

we need to virtually filter the accounts table data based on user login. User email and his accounts are in table 2. 

kindly give me a solution. 

Hi @Anonymous ,

 

it is as easy as described by @lbendlin 

You can find my example PBIX attached.

RLS1.png

RLS2.png

RLS3.png

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Anonymous
Not applicable

@mwegener  
here is my model.

johnbasha33_0-1593068027621.png

and this is the error i am getting if i try to apply security in both directions.

johnbasha33_1-1593068104784.png

 

Hi @Anonymous ,

 

doesn't it work without the checkbox?

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Anonymous
Not applicable

@mwegener @harshnathani @lbendlin @sturlaws 
thank you all for your time on this. 
this might work for now.

 

now we have aroung 100 K records in account table.

 

each account might be shared with multiple users.

for instance, if one account is shared by 10 users it means 10 rows.

likewise if we have 100 records vs 10 users it will be 100 * 10.

 

future maintanance of the dataset will be nightmare, what should be solution to handle this ? at the same time need to use the same RLS functionality.

looking forward to hear from you.

Hi @Anonymous ,

 

you could group the users and accounts into profiles, like in this blog post.

https://radacad.com/what-do-you-need-to-implement-dynamic-row-level-security-in-power-bi

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Anonymous
Not applicable

@mwegener 
@lbendlin  thank yuo so much, with out checkbox it did worked i am validating the data.

 

i didn't think that this is so easy, all day writing complex DAX. fingers crossed and hope this should work.
i will let you know by EOD the update.

Anonymous
Not applicable

@sturlaws 
yeah this is what something i am expecting.

VAR _account_id =
    CALCULATETABLE (
        VALUES ( 'table1'[account_d] ),
        FILTER ( 'table2','table2'[email] = USERPRINCIPALNAME () )
    )
RETURN
    'Table1'[account_id] IN _account_id

where whould i use this DAX to filter? in table 1(fact) or table2(user table) ? 

Anonymous
Not applicable

Thank you Marcus, well in my scenario, i have already used apply security check box to another, so i cant use it here. Give me sometime, i will test again and i will post my data model picture. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors