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

Filter by concatenated columns for RLS

Hi everyone

I have the following security table(sql) for my rls, I want to filter a table based on this 

UserPrincipalNameSite
usu1@example.coms1,s3,s6
usu2@example.coms2,s19,s23
usu3@example.coms3,s4

but, I couldn't filter by this Site column

and the next table is what i want to filter based on this security table

RegionCountrySite
Aas2
Abs1
Bcs19
Bds3
Ces4

 

 I think I was getting an error due I am using an IN operator but what my Site is returning me is kind of this "s1,s2,s3", so which will be the best option to do it?

 

Thank you in advance.

 

2 ACCEPTED SOLUTIONS
jdbuchanan71
Super User
Super User

@Anonymous 

Your filter expression could be something like this (you will need to change the names of the tables to match your model).

 

VAR _UPN =
    USERPRINCIPALNAME ()
RETURN
    CONTAINSSTRING (
        LOOKUPVALUE ( Users[Site], Users[UserPrincipalName], _UPN ),
        Sites[Site]
    )

 

And you would apply that to the Sites table.

 

jdbuchanan71_1-1602172154584.png

jdbuchanan71_3-1602172190230.png

Although there is a weakness in doing it this way because PowerBI sees s2 in 's1,s23' so it is giving a false match.

If that is really how your site ID's are you may need to put in leading 0's  's02' instead of 's2' or you could split the sites in the users table then unpivot them to get 1 row per user/site pair.

 

 

 

 

View solution in original post

v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

When  we see the result as usu2@example.com,we should see S2,S19 and S23, however in 's reply we can see S1.

You may try my way, transform your User Table and build an RLS.

Splite Site column in rows in Power Query Editor.

Build a relationship between two site columns in two tables.

Try this Dax expression.

[Site] = 
CALCULATE (
    MAX(Data[Site]),
    FILTER (
        Users,
        Users[UserPrincipalName] = USERPRINCIPALNAME()
            && Users[Site] = Data[Site]
    )
)

 See the result as usu2@example.com.

Result:

1.png

You can download the pbix file from this link: Filter by concatenated columns for RLS

 

Best Regards,

Rico Zhou

 

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

 

View solution in original post

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

When  we see the result as usu2@example.com,we should see S2,S19 and S23, however in 's reply we can see S1.

You may try my way, transform your User Table and build an RLS.

Splite Site column in rows in Power Query Editor.

Build a relationship between two site columns in two tables.

Try this Dax expression.

[Site] = 
CALCULATE (
    MAX(Data[Site]),
    FILTER (
        Users,
        Users[UserPrincipalName] = USERPRINCIPALNAME()
            && Users[Site] = Data[Site]
    )
)

 See the result as usu2@example.com.

Result:

1.png

You can download the pbix file from this link: Filter by concatenated columns for RLS

 

Best Regards,

Rico Zhou

 

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

 

jdbuchanan71
Super User
Super User

@Anonymous 

Your filter expression could be something like this (you will need to change the names of the tables to match your model).

 

VAR _UPN =
    USERPRINCIPALNAME ()
RETURN
    CONTAINSSTRING (
        LOOKUPVALUE ( Users[Site], Users[UserPrincipalName], _UPN ),
        Sites[Site]
    )

 

And you would apply that to the Sites table.

 

jdbuchanan71_1-1602172154584.png

jdbuchanan71_3-1602172190230.png

Although there is a weakness in doing it this way because PowerBI sees s2 in 's1,s23' so it is giving a false match.

If that is really how your site ID's are you may need to put in leading 0's  's02' instead of 's2' or you could split the sites in the users table then unpivot them to get 1 row per user/site pair.

 

 

 

 

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.