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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Titatovenaar2
Helper III
Helper III

DAX: USERNAME() in measure to get rank from table specified to the user (.pbix included)

Hi guys,

 

I'm currently unable to show the top 2 'calls' (just a number in a table) specified to the User currently logged in, by using USERNAME(). With the current logic I came up with I receive the following error:

"CUSTOMDATA, USERNAME, USERCULTURE and USERPRINCIPALNAME functions are not supported in calculated tables/columns. These functions may only be used in Measures or in the AllowedRowsExpression."

 

This is the result I want to achieve (also within included PBIX File).

The Green box is the result I want to achieve, but currently the Red box is where the error shows up when using USERNAME(), because in the example below uses the string "Irene" instead of USERNAME().

UserName = "Irene" --because with USERNAME() the other measures crash

Titatovenaar2_0-1624869755656.png

This is the DAX I use:

CallsPerUser_FilterMsr = 
CALCULATE( 
    SUM(CallsPerUser[CallsPerUser_Filter]), 
    FILTER(CallsPerUser, CallsPerUser[User] = [UserName])) 
CallsRank = 
RANKX(ALL(CallsPerUser),[CallsPerUser_FilterMsr],,DESC,Skip)
Calls Top 2 = CALCULATE([CallsPerUser_FilterMsr],FILTER(CallsPerUser,[CallsRank]<=2))

 

Also using visual level filter with Top N doesn't work with what I tried, because you'll get the reports with in general the highest Calls, instead of specified to the user.

Titatovenaar2_1-1624870444663.png

 

Any suggestions / workarounds?

PBIX File 

 

Kind regards,

Igor

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Titatovenaar2 , change this one and then try and visual level filter on CallsRank

 

CallsRank = 
RANKX(ALLselected(CallsPerUser[Report]),[CallsPerUser_FilterMsr],,DESC,Skip)

r

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@Titatovenaar2 , change this one and then try and visual level filter on CallsRank

 

CallsRank = 
RANKX(ALLselected(CallsPerUser[Report]),[CallsPerUser_FilterMsr],,DESC,Skip)

r

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.