Search code examples
powerbi-embeddedrow-level-security

Embedded Power BI: Add Multiple Users in Row Level Security and assign different roles


I have downloaded App Owns Data from github - https://github.com/Microsoft/PowerBI-Developer-Samples. I have added Row Level Security by adding the following line:

generateTokenRequestParameters =  new GenerateTokenRequest("View", null, 
       identities: new List<EffectiveIdentity>{new EffectiveIdentity(username: "username", roles: new List<string> { "Role A"}, datasets: new List<string> { report.DatasetId })});

Currently, I can add only one username at a time. Is there any way using which I can multiple users and assign different roles to them? Any help is appreciated!


Solution

  • You need to add row level security by adding roles in power bi desktop -

    1. Modeling => Manage Roles
    2. Create
    3. Give your role a name e.g Role A
    4. Select a table under Tables to filter on
    5. in the Table filter DAX expression add [column_name_here] = USERNAME()
    6. The username that you pass into your GenerateTokenRequest will be passed to USERNAME()

    Adding multiple usernames to the GenerateTokenRequest would be counter intuitive as it is designed to generate a token for a single user viewing the embedded report.

    If you have different usernames in different tables for the same user then you could create a look up table where usernameA maps to username1 on table1, username2 on table 2 etc.

    If you can provide more details on your use case I'd be happy to try and help