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
andrew_hardwick
Helper III
Helper III

return Top xxx rows in table

I have a table showing users that have logged into a system. The total table has around 550 users (this can vary), and from this table I need to be able to show the ones who have logged in the most (in this case the top 392).

 

I have a table showing 2 columns, Username and number of logins.

 

UsernameCount of login
abc@domain.com9374
def@domain.com6192
ghi@domain.com2981
xyz@domain.com2510

 

Ideally I would like to add an extra column to this table, showing if they are a Top user or not. So the 392 with the highest number of logins will be flagged as a top user, the other remaining users (variable, but around 160), will not be.

 

I have tried using the formula:

 

 

Measure 2 = TOPN(392,staff,Staff[Login History.LoginTime])

 

 

 
However I get the error 'The expression refers to multiple columns. Multiple column cannot be converted to a scalar value.'
 
Any tips?
 
Thanks,
 
Andy
2 ACCEPTED SOLUTIONS

Hey, try ALL(Staff[Username]) for the table instead of just staff. You need to calculate the rank of one row against all the rows in order to check the ranking. That's why it's 1 for you.

 

Hope this helps,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

View solution in original post

Hi @andrew_hardwick ,

Please update the formula of your measure as below:

Rank =
RANKX (
    ALL ( Staff[Username] ),
    CALCULATE ( COUNT ( Staff[Login History.LoginTime] ) ),
    ,
    DESC,
    DENSE
)

Rankx.JPGBest Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
ibarrau
Super User
Super User

Hi there. The function you are looking for is RANKX. The TOPN returns a table and you need a scalar showing the ranking. Try that function like: RANKX(Table, [Measure]).

 

Regards,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Hi @ibarrau . I tried that, but rank shows as 1 each time.

 

Capture.PNG

 

The formula I used was:

Rank = RANKX(Staff,count(Staff[Login History.LoginTime]))

 

I used Count as without this, I got an error saying:

 

A single value for column 'Login History.LoginTime' in table 'Staff' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

Hi @andrew_hardwick ,

Please update the formula of your measure as below:

Rank =
RANKX (
    ALL ( Staff[Username] ),
    CALCULATE ( COUNT ( Staff[Login History.LoginTime] ) ),
    ,
    DESC,
    DENSE
)

Rankx.JPGBest Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi, yes the ALL part was the missing part, thanks!

Hey, try ALL(Staff[Username]) for the table instead of just staff. You need to calculate the rank of one row against all the rows in order to check the ranking. That's why it's 1 for you.

 

Hope this helps,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

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.