Skip to main content

Power BI

Needs Votes

Provide username function in Power Query - M or DAX calculated columns

Vote (365) Share
's profile image

on 20 May 2016 01:15:53

Being restricted to just using username () in measures (or AllowedRowsExpression) means that you cannot use the context of the current user in slicers or page level or report level filters.

Just to be clear, the desired result is not data security (that can be done through roles), it is to provide relevance. We want to be able to show a page that shows (for example) My Teams timesheet hours, perhaps next to a report page that shows an overview of the entire company.

You can provide some neat filtering using measures containing username () , but in particular, you can’t provide slicers (or page filters) that are cut down to just the list of relevant items based on the user logged in.

It would be extremely helpful if you could access the username value either via a function in PowerQuery M, or to allow username () to be referenced in a calculated column using DAX.
Trying to use username () in a calculated column currently gives the error:

"CUSTOMDATA and USERNAME functions are not supported in calculated columns. These functions may only be used in Measures or in the AllowedRowsExpression."

Perhaps there are security, functional or performance reasons why this isn't possible, but thought it worth putting forward.

Comments (40)
's profile image Profile Picture

588ab218 deaa-424e-a947-07fc4a7d2348 on 06 Jul 2020 00:18:11

RE: Provide username function in Power Query - M or DAX calculated columns

Given that PowerBI is based on Analysis Services, could we ask for an implicit "Current User" dimension, perhaps with a single hierarchy "User Details", with two levels :
1: User Details (with a single member = the current user) and Attributes: User Name, User Principal Name, User Distinguished Name
2) Group Membership: (Multiple members, one per group the current user is a member of) and Attributes: Group Display Name, Group Distinguished Name

PowerBI Desktop must be able to "inject" this dimension into every workbook, as it has knowledge of the desktop user, and if the workstation is part of a domain , it can query and populate the Group memberships

PowerBI Services should also be able to create the equivalent, as it is AzureAD aware by definition.

So "package" this concept into PowerBI, and make it available to users.

's profile image Profile Picture

d0761be7 5479-4718-8356-bf4736e0b108 on 06 Jul 2020 00:18:10

RE: Provide username function in Power Query - M or DAX calculated columns

To avoid having too much and also unnecessary data sent to clients

's profile image Profile Picture

c8336ab9 f6d5-4131-a2c3-e574fbf766a4 on 06 Jul 2020 00:12:42

RE: Provide username function in Power Query - M or DAX calculated columns

To avoid having too much and also unnecessary data sent to clients who own no privilege of having it and filtered with DAX RLS, or setting up thousands of login accounts in database engine to implement DATABASE RLS or using dmv to check login_name to filter rows, the only parameter-free way now is constructing SSAS solution which have built-in Role based row access control by setting up roles and adding domain groups/users in them. One core reason of the existence of this ability is the support of VBS in MDX, from which domain information can be accessed.
Yes for security reasons, the solutions for large user group reporting are limit.
So for database data source, either the DB team change the way Data Engine work to be like SSAS, or you power bi team adopt to the way Dataset in SSRS pagination report works.
I wonder how long you two are going to prolong with each other, it has been years so long.

's profile image Profile Picture

af2a1cc7 a751-e711-80fa-c4346bacf588 on 06 Jul 2020 00:10:33

RE: Provide username function in Power Query - M or DAX calculated columns

Does anyone know if this is even being considered?
Nice to get some acknowledgement of an idea with 340 votes...

's profile image Profile Picture

0348630a 60c0-429b-807d-8af2384b4a92 on 06 Jul 2020 00:09:57

RE: Provide username function in Power Query - M or DAX calculated columns

I found a way to implement this using a Bridge table. Here is the article on how to do it.

https://medium.com/@barrasa8/dynamic-data-masking-in-powerbi-based-on-rls-927eb6a34e5d

's profile image Profile Picture

0348630a 60c0-429b-807d-8af2384b4a92 on 06 Jul 2020 00:09:53

RE: Provide username function in Power Query - M or DAX calculated columns

I have been trying to do this in powerbi, and I tried all sort of tricks , without success, and it seems like powerbi does not allow to mask certain information depending on the user that is connecting to the report.

's profile image Profile Picture

2c6a01c6 b0c2-4111-96e0-f51949a533d3 on 06 Jul 2020 00:04:10

RE: Provide username function in Power Query - M or DAX calculated columns

Customers don't understand why this is not possible as it is a very common desired use case.

's profile image Profile Picture

c1d5f037 a512-497f-962f-07258cbbba1a on 06 Jul 2020 00:03:28

RE: Provide username function in Power Query - M or DAX calculated columns

It's insane that this feature isn't available... We've been trying to migrate from tableau to Powerbi, but without the ability to mask (NOT HIDE) data for GDPR compliance, we may need to go back

's profile image Profile Picture

72c31d6d 96d0-4038-ab59-2c0d7c68dd20 on 06 Jul 2020 00:02:04

RE: Provide username function in Power Query - M or DAX calculated columns

Hi,
I too would need this feature, please.

With kind regards,

Bogdan

's profile image Profile Picture

2bcf6be2 0447-4dd3-8e92-b5fdeb232a04 on 06 Jul 2020 00:01:21

RE: Provide username function in Power Query - M or DAX calculated columns

I would need it also.