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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
marcl2
Frequent Visitor

Tricky RLS problem, probably to solve with DAX?

Gents,

 

I have a tricky problem of RLS.

 

Let say that i have this kind of FACT_Sales table

 

2024-04-23 10_56_20-Untitled - Power BI Desktop.jpg

 

I need to put in place RLS for many users.

I usually put a security table column with usernames and the BUKRS that they have the right to see.

This time I need on top to say that the users need to see things based on the RecC column too. Of course when I use a model like below and that I say one user has the right to see BUKRS A  OR RecC A (interco), it won't show the line interco B A 25 (because of the first RLS) 😞

 

I tend to assume that the Security tables need to be disconnected and to use some DAX to pass the conditions?

Maybe with some RLS like in this video of Reza? https://www.youtube.com/watch?v=LyeAhV2665s

 

Would someone be Fit enough to tackle this challenge with me or have tips to suggest? (I might have not search google enough)

 

Of course a really Dirty solution would be to copy the Fact_Sales and separate everything, but I'm sure it could be done elegantly.

My real fact table has millions of lines, the security tables with users will have 1000s of lines and BUKRS a,nd RecC have 100s of values. So anything really manual with 1000s of roles doesn't interest me 🙂

 

2024-04-23 10_54_46-Untitled - Power BI Desktop.jpg

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @marcl2 ,

Consider adding [RecC] to the security table.

vcgaomsft_1-1713938067707.png

and the relationship:

vcgaomsft_2-1713938255345.png

then please new a rls rule:

VAR __username = USERPRINCIPALNAME ()
VAR __bukrs = CALCULATE ( MAX ( 'Security Table'[BUKRS] ), 'Security Table'[UserName] = __username )
VAR __recc = CALCULATE ( MAX ( 'Security Table'[RecC] ),'Security Table'[UserName] = __username )
VAR __result = 'Fact_Sales'[BUKRS] = __bukrs || 'Fact_Sales'[RecC] = __recc
RETURN
    __result

vcgaomsft_3-1713938347715.png

and test the rls:

vcgaomsft_4-1713938383301.png

Output:

vcgaomsft_0-1713938042407.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

View solution in original post

1 REPLY 1
v-cgao-msft
Community Support
Community Support

Hi @marcl2 ,

Consider adding [RecC] to the security table.

vcgaomsft_1-1713938067707.png

and the relationship:

vcgaomsft_2-1713938255345.png

then please new a rls rule:

VAR __username = USERPRINCIPALNAME ()
VAR __bukrs = CALCULATE ( MAX ( 'Security Table'[BUKRS] ), 'Security Table'[UserName] = __username )
VAR __recc = CALCULATE ( MAX ( 'Security Table'[RecC] ),'Security Table'[UserName] = __username )
VAR __result = 'Fact_Sales'[BUKRS] = __bukrs || 'Fact_Sales'[RecC] = __recc
RETURN
    __result

vcgaomsft_3-1713938347715.png

and test the rls:

vcgaomsft_4-1713938383301.png

Output:

vcgaomsft_0-1713938042407.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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