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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Show Current Logged in User data only

Hello Folks,

 

I am new to DAX query in Power BI and struggling to use SelectedValue - any other ways would do as well.

 

The requirement is to show the data as per the Current Logged In User - in my table, I have got the User Principal Name which I using as follows:

 

CurrentUserData =
VAR CurrentDataFilter = FILTER(TimeReport, TimeReport[UserPrincipalName] =USERPRINCIPALNAME())
RETURN
SWITCH(
TRUE(),
SELECTEDVALUE(TimeReport[UserPrincipalName] = CurrentDataFilter),
FALSE()
)

 

This is not working, hence need your help here.

 

Thanks!

 

UserPrincipalNameNameDateFunctionP1P2P3
john@thestrawberry.comJohn 01-12-2021TID555
christina@thestrawberry.comChristina02-12-2021KID51020
sarah@thestrawberry.comSarah03-12-2021AD1152
christina@thestrawberry.comChristina05-12-2021TID5515
john@thestrawberry.comJohn03-12-2021TID881

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Got the solution and credit goes to @miguelarce 
https://community.powerbi.com/t5/Developer/RLS-vs-Filter-for-current-user/m-p/329584


Measure1
WhoIsWatching = USERPRINCIPALNAME() 
(that is email style usernames, or you can use USERNAME() for windows style users)

fmourtaza_0-1638770845718.png

 


Measure 2
FilterByViewer = IF(selectedvalue(table[email])=[WhoIsWatching],1,0)

fmourtaza_1-1638770915538.png

 


Drag Measure 2 as a filter for visual, select advanced filtering and set it to 
"Show items when value IS 1"

fmourtaza_2-1638770961734.png

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Got the solution and credit goes to @miguelarce 
https://community.powerbi.com/t5/Developer/RLS-vs-Filter-for-current-user/m-p/329584


Measure1
WhoIsWatching = USERPRINCIPALNAME() 
(that is email style usernames, or you can use USERNAME() for windows style users)

fmourtaza_0-1638770845718.png

 


Measure 2
FilterByViewer = IF(selectedvalue(table[email])=[WhoIsWatching],1,0)

fmourtaza_1-1638770915538.png

 


Drag Measure 2 as a filter for visual, select advanced filtering and set it to 
"Show items when value IS 1"

fmourtaza_2-1638770961734.png

 

Hi fmourtaza,

do you have a test pbix file to share? it doesnt seem to work for me.

Thanks

Anonymous
Not applicable

Almost there - I am now able to filter the data based on the Current Logged In user.

 

Next is I wanna show Multiple Columns in my Visual (see a line with Values) - in the below case I get only 1 value - I tried to return a complete row but it throws me the error "Multiple columns cannot be converted to a scalar value"  - any other way to show multiple columns?

 

CurrentUserData =
VAR CurrentUserState = CALCULATE(MAX(TimeReport[UserPrincipalName]),FILTER(TimeReport, TimeReport[UserPrincipalName] = USERPRINCIPALNAME()))
RETURN
IF(
SELECTEDVALUE(TimeReport[UserPrincipalName]) = CurrentUserState,
Values(TimeReport[Neukunden_Akquise_Produkte])
)
 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.