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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
marcl2
Regular 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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.