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
dinesh123
Helper II
Helper II

Embedded RLS

@tamerj1 
Hi all,

We are using Embedding Power BI. In that we are using RLS. In general secenarios, RLS works based on Username(), Userprincipalname() where it will return either user name or user email id. With embedded power BI RLS scenario, we can get any value in the username() as part of the requirement on which value we should filter the data. As part of RLS, i am getting a string with list of values where user can see the report only with list of values corresponding data. Here string contains "Program1,Program2,Program3.." like so on. I should able to read this string and filter the data for those program related data. As i get the list of values in the form of string i need to store this as a list or column and then only can filter.

 

For Example:

{

  "accessLevel": "View",

  "datasetId": "cfafbeb1-*****-a46fb27ff229",

  "identities": [

    {

      "username": "Program1",

      "roles": [

        "sales"

      ],

      "datasets": [

        "cfafbeb1-******-a46fb27ff229"

      ]

    }

  ]

}

Here we are passing one Program from Java SDK. We were able to apply RLS for one value. However,

{

  "accessLevel": "Create",

  "datasetId": "cfafbeb1-8******e-a46fb27ff229",

  "identities": [

    {

      "username": "Program1,Program2,Program3,….",

      "roles": [

        "sales"

      ],

      "datasets": [

        "cfafbeb1-80*****e-a46fb27ff229"

      ]

    }

  ]

}

But we want to pass more programs from username but we are getting output as single string not as individual Programs.

Here we need to pass multiple values from Username and read it as individual Programs as values in Embedded PowerBI not as single string.

 

For reference: https://learn.microsoft.com/en-us/power-bi/developer/embedded/cloud-rls

2 ACCEPTED SOLUTIONS
tamerj1
Super User
Super User

Hi @dinesh123 
Please try

[Program] IN
VAR String = USERNAME ( )
VAR Items =
    SUBSTITUTE ( String, ",", "|" )
VAR Length =
    COALESCE ( PATHLENGTH ( Items ), 1 )
VAR T1 =
    GENERATESERIES ( 1, Length, 1 )
RETURN
    SELECTCOLUMNS ( T1, "Project", PATHITEM ( Items, [Value] ) )

View solution in original post

@dinesh123 
Please try

=
[Child_code]
    IN
    VAR Input =
        USERNAME ()
    VAR Length =
        LEN ( Input )
    VAR IndexSep =
        COALESCE ( FIND ( ":", Input, 1, BLANK () ), Length )
    VAR String =
        IFERROR ( RIGHT ( Input, Length - IndexSep ), BLANK () )
    VAR String2 =
        COALESCE (
            String,
            CONCATENATEX ( VALUES ( ChildOrg[Child_code] ), ChildOrg[Child_code], "," )
        )
    VAR Items =
        SUBSTITUTE ( String2, ",", "|" )
    VAR Length =
        COALESCE ( PATHLENGTH ( Items ), 1 )
    VAR T1 =
        GENERATESERIES ( 1, Length, 1 )
    RETURN
        SELECTCOLUMNS ( T1, "Project", PATHITEM ( Items, [Value] ) )

View solution in original post

31 REPLIES 31

@dinesh123 

Please check your email 

Hi @tamerj1 Sorry for inconvinience,  Resent the link please connect.

I have resent zoom link.

Hi @tamerj1 ,
Thank you for your help over the call.
When I try pass the Same code with Java SDK its not working. The code i'm passing is "P1,P2:" Where P1 and P2 are program codes and after collon no child code so kept empty. 

Here is the code for Child code Managerole RLS. 

[Child_code] IN

Var Input = Username()
Var IndexSep = FIND(":", Input, 1, BLANK())

VAR String = RIGHT(Input,LEN(Input)-IndexSep)


Var String2 = COALESCE(String, Concatenatex(values(ChildOrg[Child_code]),ChildOrg[Child_code],","))

VAR Items =
SUBSTITUTE ( String2, ",", "|" )
VAR Length =
COALESCE ( PATHLENGTH ( Items ), 1 )
VAR T1 =
GENERATESERIES ( 1, Length, 1 )
RETURN
SELECTCOLUMNS ( T1, "Project", PATHITEM ( Items, [Value] ) )

@dinesh123 
Please try

=
[Child_code]
    IN
    VAR Input =
        USERNAME ()
    VAR Length =
        LEN ( Input )
    VAR IndexSep =
        COALESCE ( FIND ( ":", Input, 1, BLANK () ), Length )
    VAR String =
        IFERROR ( RIGHT ( Input, Length - IndexSep ), BLANK () )
    VAR String2 =
        COALESCE (
            String,
            CONCATENATEX ( VALUES ( ChildOrg[Child_code] ), ChildOrg[Child_code], "," )
        )
    VAR Items =
        SUBSTITUTE ( String2, ",", "|" )
    VAR Length =
        COALESCE ( PATHLENGTH ( Items ), 1 )
    VAR T1 =
        GENERATESERIES ( 1, Length, 1 )
    RETURN
        SELECTCOLUMNS ( T1, "Project", PATHITEM ( Items, [Value] ) )

Hi @tamerj1 
Can you please check email, I have mailed you.

Hi @dinesh123 
Please use

=
[ChildCode_RLS]
    IN
    VAR Input =
        USERNAME ()
    VAR Items1 =
        SUBSTITUTE ( Input, ":", "|" )
    VAR String1 =
        PATHITEM ( Items1, 2 )
    VAR String2 =
        IF (
            String1 = "",
            CONCATENATEX (
                VALUES ( ChildCode[ChildCode_RLS] ),
                ChildCode[ChildCode_RLS],
                ","
            ),
            String1
        )
    VAR Items2 =
        SUBSTITUTE ( String2, ",", "|" )
    VAR Length =
        COALESCE ( PATHLENGTH ( Items2 ), 1 )
    VAR T1 =
        GENERATESERIES ( 1, Length, 1 )
    RETURN
        SELECTCOLUMNS ( T1, "@ChildCode", PATHITEM ( Items2, [Value] ) )

Hi @tamerj1 Thank you tamer for your help.
Sorry to disturb again. I have mailed can you please check.


This code works fine.

=
[Child_code]
    IN
    VAR Input =
        USERNAME ()
    VAR Length =
        LEN ( Input )
    VAR IndexSep =
        COALESCE ( FIND ( ":", Input, 1, BLANK () ), Length )
    VAR String =
        IFERROR ( RIGHT ( Input, Length - IndexSep ), BLANK () )
    VAR String2 =
        COALESCE (
            String,
            CONCATENATEX ( VALUES ( ChildOrg[Child_code] ), ChildOrg[Child_code], "," )
        )
    VAR Items =
        SUBSTITUTE ( String2, ",", "|" )
    VAR Length =
        COALESCE ( PATHLENGTH ( Items ), 1 )
    VAR T1 =
        GENERATESERIES ( 1, Length, 1 )
    RETURN
        SELECTCOLUMNS ( T1, "Project", PATHITEM ( Items, [Value] ) )



Hi @tamerj1 Kudos!!!!!!
Code is working fine exactly as we expected to be. Thank you very much once again for your help and support.

Hi @tamerj1 Kudos 
Code is working fine exactly how we expected to be. Thank you so much once again for your time and support. 

@tamerj1 
Hi Tamer,
Thanks for your immediate respose on weekend also. It is working fine. Thanks alot!!!!

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.