Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
olimilo
Responsive Resident
Responsive Resident

Getting error when using USERPRINCIPALNAME() to filter content as part of a calculated column

I have a table that contains User IDs and an Region value for the data that they can access in our dashboard.

 

NameDepartmentUserIDRegionAccess
Jane DoeOperations12345Global
John DoeTraining12346EMEA
June DoeOperations12347EMEA

 

Basically, how we would like this to work is, we will pull the current user's RegionAccess value using their USERPRINCIPALNAME() from this table and filter the master data according to their ID's equivalent RegionAccess value. The IDs are not (and cannot) be found in our master data so this is the only way for us to filter this out.

 

I tried making a custom column with the following formula however I am getting a usage error with the USERPRINCIPALNAME value:

 

 

Column = CONTAINSSTRING('MasterData'[Region]), LOOKUPVALUE('UserData'[RegionAccess], 'UserData'[EmailAddress], USERPRINCIPALNAME()))

CUSTOMDATA, USERNAME, USERCULTURE and USERPRINCIPALNAME functions are not supported in calculated tables/columns. These functions may only be used in Measures or in the AllowedRowsExpression.

 

 

I tried using the same DAX expression as the RLS table filter instead however it doesn't seem to be working as intended because when I use View As another user, the data is not filtered. Is there some other approach I can do here? I was able to do something similar on a PBI Paginated Report so I was hoping I could replicate it here.

1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@olimilo 
You cannot use USERPRINCIPALNAME () in a column, because this function returns a dynamic result based on your login account. 

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
V-pazhen-msft
Community Support
Community Support

@olimilo 
You cannot use USERPRINCIPALNAME () in a column, because this function returns a dynamic result based on your login account. 

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@olimilo , I think you can use USERPRINCIPALNAME in a measure, not in a column

AllisonKennedy
Super User
Super User

@olimilo Have you typed an email into the view as roles box? You need to tick both the top option with the text box -write your email or a sample user email in that box, then ALSO tick the box next to the role you wish to test. 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.