Forum Discussion
Username function error
- Anonymous1 year ago
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 [email protected] 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
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 [email protected] 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