cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ranausman Frequent Visitor
Frequent Visitor

Finding First Name or Last name using DAX like @Username

Hi, 

I understand that PowerBI records name of all the users who are logged into the app. I am using RLS on username 

I want to develop a greeting where I greet them with their name such as:

 

Good Afternoon Usman

 

Is it possible?

I found this solution but it doesn't work. 

 

Greeting1 = 
VAR user = USERNAME()
VAR display = LOOKUPVALUE(Table1[User],Table1[Email],user)
VAR hour = HOUR(NOW())
VAR minute = MINUTE(NOW())
VAR prefix = SWITCH(
                    TRUE(),
                    hour<12,"Good morning ",
                    hour>=12 && hour<17,"Good afternoon ",
                    "Good evening "
             )
RETURN CONCATENATE(prefix,display)

 

7 REPLIES 7
Stachu Super Contributor
Super Contributor

Re: Finding First Name or Last name using DAX like @Username

USERNAME() has the domain as a prefix, do you account for that in your table?
https://docs.microsoft.com/en-us/dax/username-function-dax

you can also try with USERPRINCIPALNAME()

https://dax.guide/userprincipalname/

 

Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

ranausman Frequent Visitor
Frequent Visitor

Re: Finding First Name or Last name using DAX like @Username

Both functions that you have mentioned doesn't return me any family name. I am little unsure if it can actually be retrieved?

Stachu Super Contributor
Super Contributor

Re: Finding First Name or Last name using DAX like @Username

I assumed that you have some dictionary table that allows to find the name based on the USERNAME() or the other function. Is that correct?

Usernames don't have to be based on the names/surnames, so returning the id seems the logical solution here

 

Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

ranausman Frequent Visitor
Frequent Visitor

Re: Finding First Name or Last name using DAX like @Username

Okay this makes sense, so in that case, I have following columns in my dataset.

 

NameCompanyemail
John Smithjohn.smith@xyz.com
Brown Fox

brown.fox@xyz.com

 

Given the above table, can we do that it searches for Username in company email, and if matches, display Name? If yes, what would be the dax?

Stachu Super Contributor
Super Contributor

Re: Finding First Name or Last name using DAX like @Username

what format does USERPRINCIPALNAME() return for you? I assume it would be something like user@xyz.com
If that's the case then this should work:

HelloUser =
"Hello "
    & CALCULATE (
        FIRSTNONBLANK ( 'Table'[Name], TRUE ),
        'Table'[Companyemail] = USERPRINCIPALNAME ()
    )
Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

 

Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

ranausman Frequent Visitor
Frequent Visitor

Re: Finding First Name or Last name using DAX like @Username

Thanks for helping out, however it doesn't seem to be working. It only returns "HelloUser", that's all, and yes userprincipalname returns me email such as user@xyz.com. 

Btw I am using Username for Dynamic RLS and not userpricipalname

 

 

Highlighted
Stachu Super Contributor
Super Contributor

Re: Finding First Name or Last name using DAX like @Username

it cannot return HelloUser beacause that's the measure name - have you added this syntax as a new measure? It's completely unrelated to RLS

 

Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Helpful resources

Announcements
New Topics Started Badges Coming

New Topics Started Badges Coming

We're releasing new versions of the badge that everyone's talking about. ;) Check your inbox for notifications.

MBAS 2020

Save the new date (and location)!

Our business applications community is growing—so we needed a different venue, resulting in a new date and location. See you there!

Difinity Conference

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)