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
Mahamood0218
Helper II
Helper II

How to display login user name in power bi report with out using Row level security

Hi,

I need to display login user name without using Row level Security,by automatically

1 ACCEPTED SOLUTION

 

Ah, okay, I'm with you now.

You would need to have a dimension table that contains all users' USERNAME or USERPRINCIPALNAME and this table would need to be related to all the other tables in your data model, maybe using Employee ID or similar.

 

You could then create a filter measure against this dimension table, something like this:

_userFilter =
VAR __currentUSER = USERNAME()  // or USERPRINCIPALNAME()
RETURN
IF(
  MAX(userDimension[userName]) = __currentUSER,
  1,
  0
)

 Where you apply this measure to the visual-level filters and set it to __userFilter = 1.

 

Alternatively, you could write the same logic into each of your measures instead, something like this:

_filteredSales =
VAR __currentUSER = USERNAME()  // or USERPRINCIPALNAME()
RETURN
CALCULATE(
  SUM(salesTable[Sales]),
  FILTER(
    userDimension,
    userDimension[userName] = __currentUser
  )
)

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

6 REPLIES 6
BA_Pete
Super User
Super User

Hi @Mahamood0218 ,

 

You can use the USERNAME() or USERPRINCIPALNAME() functions in measures, literally just the function:

 

_userName = USERNAME()

_userPrincipleName = USERPRINCIPALNAME()

 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hi @BA_Pete ,

Actually i used userprincipalname() dax functioin after that generally we r going to creating the RLS there we are enter user mail id's but my requirement is without using Row level security need to display user login name

Mahamood0218_1-1645453298952.png

could you please suggest is there any logic 

Mahamood0218_2-1645453510130.png

 

Hi @Mahamood0218 ,

 

I don't really understand what you mean by "without using Row Level Security". Both of the functions I gave you can be used independently in measures and placed in cards etc.

 

You can use either USERPRINCIPALNAME or USERNAME to get the user's login name, you just need to either extract text before '@' delimiter for USERPRINCIPALNAME, or after the domain name '/' for USERNAME.

 

If you want the person's actual forename/surname, then you would probably need to build a dimension table from your Active Directory records, something like this:

 

1) In PQ, connect to your Active Directory domain.

2) Find the User table and import it.

3) Find the [User] column that has nested records in it, expand, and select the [mail] column to expand.

4) Select [displayName] and [mail] and remove other columns.

 

You should now be able to use this as a dimension table and relate it to a calculated table that contains USERPRINCIPALNAME to translate it to a 'friendly' name.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hi ,

I have a case scenario :
One Customer application ,when user logs in and let's say he is a Staff he should see the report for staff ,if he is manager then  he should see that for manager report .

https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-sample-for-customers?tabs=net-cor...

I have created 3 reports one for Staff another for manager and so on all are in one workspace.
I have gone through the doc as mentioned and using Apps own data concept , i have completed all the steps till Step 8 ,but then when i am logged in to the application i can't see the report there..Is there anything else i need to do ?

What's next i have to do for interaction?

@BA_Pete  my requirement is i have 10HR records in that records 5 records are availble in the name of Shaik and remaining 5 records are available in the name "Pete",then we ever i open the report in Power BI Service i will get only my records in the name of shaik ,after that when ever u open the same report at a time u will get only 5"Pete records"  here my question is ,is there any logic to get particular records(along with our official mailid) by using userpricipalname()

Mahamood0218_0-1645510635950.pngMahamood0218_1-1645510675604.png

when i login with my userid i need out like below

Mahamood0218_2-1645510844590.png

 

 

 

 

Ah, okay, I'm with you now.

You would need to have a dimension table that contains all users' USERNAME or USERPRINCIPALNAME and this table would need to be related to all the other tables in your data model, maybe using Employee ID or similar.

 

You could then create a filter measure against this dimension table, something like this:

_userFilter =
VAR __currentUSER = USERNAME()  // or USERPRINCIPALNAME()
RETURN
IF(
  MAX(userDimension[userName]) = __currentUSER,
  1,
  0
)

 Where you apply this measure to the visual-level filters and set it to __userFilter = 1.

 

Alternatively, you could write the same logic into each of your measures instead, something like this:

_filteredSales =
VAR __currentUSER = USERNAME()  // or USERPRINCIPALNAME()
RETURN
CALCULATE(
  SUM(salesTable[Sales]),
  FILTER(
    userDimension,
    userDimension[userName] = __currentUser
  )
)

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




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.

Top Solution Authors
Top Kudoed Authors