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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Lebombaa
New Member

RLS with parent child hierarchy

Hello!

 

I want to implement RLS from a hierarchy path calculated by the path function. Hierarchy is a column calculated with the path function and OrgID is the child node an dcontains letters and numbers.

 

this is my DAX code in the Dax editor for RLS.

PATHCONTAINS(

    Accesstree[Hierarchy],

    MaxX(

        Filter(

            Accesstree,

            [Email] = USERPRINCIPALNAME()

        ),

        Accesstree[OrgID]

    )

)

 

The problem here is when I assign this role and log in with an email, it misses some parts because people can have an email linked to several OrgIDs, and then I only see the OrgID that has the highest value because of MaxX function. How can I rewrite the code to fix this? When peolpe log in, they should be able to see all of the rows with their own OrgID and the ones that are under them in the hierarchy/path.

 

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi there @Lebombaa 

Something like this should do the trick:

VAR UPN = USERPRINCIPALNAME()
VAR CurrentUserOrgID =
    CALCULATETABLE (
        SELECTCOLUMNS ( VALUES ( Accesstree[OrgID] ), "@CurrentUserOrgID", Accesstree[OrgID] ),
        Accesstree[Email] = UPN,
        REMOVEFILTERS ()
    )
VAR CurrentHierarchy =
    Accesstree[Hierarchy]
RETURN
    NOT ISEMPTY (
        FILTER (
        CurrentUserOrgID,
            PATHCONTAINS(
                CurrentHierarchy,
                [@CurrentUserOrgID]
            )
    )
)

The basic idea is that CurrentUserOrgID is a table of all OrgID values for the current user. Then we check whether the current row's path contains any of those, and if so return TRUE, otherwise FALSE.

 

Does this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi there @Lebombaa 

Something like this should do the trick:

VAR UPN = USERPRINCIPALNAME()
VAR CurrentUserOrgID =
    CALCULATETABLE (
        SELECTCOLUMNS ( VALUES ( Accesstree[OrgID] ), "@CurrentUserOrgID", Accesstree[OrgID] ),
        Accesstree[Email] = UPN,
        REMOVEFILTERS ()
    )
VAR CurrentHierarchy =
    Accesstree[Hierarchy]
RETURN
    NOT ISEMPTY (
        FILTER (
        CurrentUserOrgID,
            PATHCONTAINS(
                CurrentHierarchy,
                [@CurrentUserOrgID]
            )
    )
)

The basic idea is that CurrentUserOrgID is a table of all OrgID values for the current user. Then we check whether the current row's path contains any of those, and if so return TRUE, otherwise FALSE.

 

Does this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Yes it worked thank you!

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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