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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors