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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
olimilo
Post Prodigy
Post Prodigy

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
Anonymous
Not applicable

@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
Anonymous
Not applicable

@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

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
AllisonKennedy
Community Champion
Community Champion

@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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.