1
votes

I'm using the power bi embedded Row Level Security. According to the documentation given here we need to add a role in the power bi desktop and use a DAX expression like [ColumnName] = USERNAME(). So that this filter will work when the user has that particular role.

My question is is there any chance to use the DAX expression anywhere to filter data using the Username directly?

Thanks in advance

1
Are you asking about DirectQuery in data connectivity mode? Or would you like to import all data using import mode and filter data by user in visual which presents data?Przemyslaw Remin
Thanks for you reply. I'm using DirectQuery. Basically I want to restrict the data using the USERNAME() without the roleJoe Samraj
Have you seen Patrick's video on the subject youtube.com/watch?v=9wN33rTaiB4Przemyslaw Remin
Yes I did, if you see that video at 05:34 he add the expression [Username] = USERNAME() within the "Security" role group. It works. But my question is, is there any way to do that same without the security role group, so that even though the user is not having that role the data will be filtered to what is related to himJoe Samraj
you can use custom data to filter data based off a userid/login without having to create a security role. This would just eb a string passed through the API docs.microsoft.com/en-us/dax/customdata-function-daxStelioK

1 Answers

3
votes

Accessing usernames

If User owns data is used for embedding, then while authenticating, the username is accessible in the code. Or, even if using App owns data, if you authenticate your users while accessing your portal, then you can get the username while authentication.

Below is an example on JS

oCommon.authContext.getCachedUser();

Below is an example in C#

HttpContext.Current.User.Identity.Name;

Filtering in the embedded report

Further, by using filtering capabilities of Power BI embedding, the report can be filtered on the username value fetched during authentication.

Avoid flickering

You will be able to apply the filter after the report embeds, if you use powerbi.embed(). Instead use the concept of phased embedding, where before the report even renders, you can apply the filter. So apply the filters after load() and before render(). This will avoid the flicker that you may have with filtering after powerbi.embed().