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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
HELLOVARAS4
Frequent Visitor

Username function error

Hello,

 

I have an error with a measure that I dont know how to correct. It works on one page but not on another in the same PBIX file. Below is the DAX and attached in the error. It just stopped working. I have the same measures on all my reports and it works fine. Any help will be appreciated. 

DAX:

_Username =
    VAR _Name = USERNAME()
    VAR _Name2 = LEFT( _Name , SEARCH("@", _Name )-1)
RETURN
    CONCATENATE( "Welcome " , LEFT( _Name , SEARCH(".", _Name2 )-1) & "!"
    )
 
Error:Username_Error.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @HELLOVARAS4 ,

 

This is because username() will return a user in the format of DOMAIN\User and userprincipalname() will return a user in the format of user@contoso.com inPower BI Desktop

 

Note: Within the Power BI service, username() and userprincipalname() will both return the user's User Principal Name (UPN). This looks similar to an email address.

 

To solve this problem, you can use the IFERROR function to handle the error condition.

 

For example, if the SEARCH function can't find the target character, it will return 10 instead of an error. You can replace 10 with a different default value or processing logic as needed.

_Username = 
    VAR _Name = USERNAME()
    VAR _Name2 = LEFT( _Name , IFERROR(SEARCH("@", _Name ),10)-1)
RETURN
    CONCATENATE( "Welcome " , LEFT( _Name , IFERROR(SEARCH(".", _Name2 ),10)-1) & "!"
    )

 

 

Best regards,

Mengmeng Li

View solution in original post

4 REPLIES 4
Tahreem24
Super User
Super User

@HELLOVARAS4 Or you could also try this DAX measure:

 

Measure =
CONCATENATE("Welcome " & UPPER(LEFT(USERPRINCIPALNAME(),1)),MID(USERPRINCIPALNAME(),2,SEARCH(".",USERPRINCIPALNAME())-2))
Tahreem24_0-1733898928209.png

 

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard
Tahreem24
Super User
Super User

@HELLOVARAS4 Try this DAX:

 

Measure = CONCATENATE( "Welcome " , LEFT( USERPRINCIPALNAME() , SEARCH("@", USERPRINCIPALNAME())-1))
 
Tahreem24_0-1733898439946.png

 

 
Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard
Anonymous
Not applicable

Hi @HELLOVARAS4 ,

 

This is because username() will return a user in the format of DOMAIN\User and userprincipalname() will return a user in the format of user@contoso.com inPower BI Desktop

 

Note: Within the Power BI service, username() and userprincipalname() will both return the user's User Principal Name (UPN). This looks similar to an email address.

 

To solve this problem, you can use the IFERROR function to handle the error condition.

 

For example, if the SEARCH function can't find the target character, it will return 10 instead of an error. You can replace 10 with a different default value or processing logic as needed.

_Username = 
    VAR _Name = USERNAME()
    VAR _Name2 = LEFT( _Name , IFERROR(SEARCH("@", _Name ),10)-1)
RETURN
    CONCATENATE( "Welcome " , LEFT( _Name , IFERROR(SEARCH(".", _Name2 ),10)-1) & "!"
    )

 

 

Best regards,

Mengmeng Li

hnguy71
Super User
Super User

Hi @HELLOVARAS4 ,


Seems the issue is stemming from your missing "." character. Let's try to debug it and see which part of your search is causing your error and then we can fix it. What does this return you?

_Username =
    VAR _Name = USERNAME()
    VAR _Name2 = LEFT( _Name , SEARCH("@", _Name )-1)
RETURN
_Name2


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.