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 Help

Hi All,

 

Im an RLS noob so to speak and trying to figure things out, so I have built a Security table something like this:

 

Email:Account:RegionCountry:
User1@users.comAppleEUROPEFRANCE
User1@users.comAppleEUROPEGERMANY
User2@users.com EUROPE 
User3@Users.com  ITALY
User4@Users.com   

 

So I have put formula into rules that check based on a formula to against USERPRINCIPALNAME if they have a match

 

IE Account: 

 

 

 

[Account]
IN CALCULATETABLE (
VALUES ( SECURITY[Account] ),
FILTER (
ALL ( SECURITY ),
SECURITY[Email] = USERPRINCIPALNAME()
)
)


And that works... for user1 only... for users 2,3 &4 they dont have an account set and as such need to ignore that filter.

 

I tried adding if(isblank( to the above but either I didnt do it right or it doesnt work there.

 

Is this possible?

 

Basically I want to build in potential rules for those 3 columns and if they are NOT NULL then the rule applies if it is NULL then I want it to skip that rule.

 

Makes sense I hope?

 

Any help/suggestions MOST welcome.

 

Thanks,

 

 

11 REPLIES 11
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

Please try this:

[Account] =
IF (
    SECURITY[Account] <> BLANK (),
    CALCULATE (
        MAX ( SECURITY[Account] ),
        FILTER ( SECURITY, SECURITY[Email] = USERPRINCIPALNAME () )
    )
)

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hey,

 

Sorry only getting back to this now... I modified what you suggested to fix an error about multiple values with:

 

[Account] =
IF (
LOOKUPVALUE(SECURITY[Account],SECURITY[Email],USERPRINCIPALNAME ()) <> BLANK (),
CALCULATE (
MAX ( SECURITY[Account] ),
FILTER ( SECURITY, SECURITY[Email] = USERPRINCIPALNAME () )
)
)

 

However this still not working, if the field SECURITY[Account] is blank for a user then it still basically prevents them from seeing anything at all, again the intention here is if I leave the Account field blank then that rule should NOT apply to them.

 

Thanks again for all the help to date!

 

Regards,

Anonymous
Not applicable

This has become even more critical for me to solve if possible now as I just realised an assumption I had made is wrong on RLS... I had thought if I had 3 RLS Rulesets like the above for example called:

 

Account Security

 

And another more or less identical formula but for Country Security and I put a user into both rules then it would limit the data both ways... but it appears thats not the case and when you test as someone in both rules it completly ignores BOTH rules? In Desktop anyway.

Anonymous
Not applicable

Apologies for the bump here, really need help on this!

 

Thanks,

v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

How about using dax below?

[Account] =
CALCULATETABLE (
    VALUES ( SECURITY[Account] ),
    FILTER (
        ALL ( SECURITY ),
        SECURITY[Email] = USERPRINCIPALNAME ()
            && SECURITY[Account] <> BLANK ()
    )
)

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks so much for your reply,

 

I just tried this as

 

[Account]
IN CALCULATETABLE (
VALUES ( SECURITY[Account] ),
FILTER (
ALL ( SECURITY ),
SECURITY[Email] = USERPRINCIPALNAME()
&& SECURITY[Account] <> BLANK ()
)
)

 

and the table still stays filtered? (doesnt work as an = either sadly 😞

@Anonymous , as far as I understand, your intention is not to filter at all, if the account is empty. You have to use then logical OR instead of AND.

 

 

 

[Account] IN
CALCULATETABLE (
    VALUES ( SECURITY[Account] ),
    FILTER (
        ALL ( SECURITY ),
        SECURITY[Email] = USERPRINCIPALNAME ()
            || ISBLANK(SECURITY[Account])
    )
)

 

 

 

Anonymous
Not applicable

Thanks @vik0810 

 

That returns nothing at all though, What I want to happen is the filter to basically leave everything UNFILTERED. 

Anonymous
Not applicable

Im starting to wonder is what im hoping unrealistic / unachievable using RLS?

@Anonymous ,

 

Have you solved your issue by now? If you have, could you please help mark the correct answer to finish the thread? Your contribution will be much appreciated.

 

Regards,

Jimmy Tao

Anonymous
Not applicable

How even can I do the if to say if BLANK (or any specific defined value) then filter nothing? Google is not my friend for this answer it seems.

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.