Smart003
Smart003

Reputation: 1119

how to select top N records in power bi

The data set is as follows

raw data set

i have written a measure which will make the sum of mark column

DAX_mark_sum=sum(mark)

I got the following result as expected when used the table visual

result

Now I need the top 2 records order by mark sum desc

To achieve the result i have tried like 1. mark the measure as "don't summarize" 2. visual filters----top N selected---> Placed 2 records.

but i got duplicates....Please help me with this one

thanks in advance

Upvotes: 1

Views: 13307

Answers (2)

StelioK
StelioK

Reputation: 1781

If you are trying to break ties in your 'Top N' ranking try something like this:

Top 2 Emp Id :=
CALCULATE ( TOPN ( 2, VALUES ( 'Table'[Emp_Id] ), [DAX_mark_sum] + RAND () ) )

Rand() will add a number between 0 and 1 to your [DAX_mark_sum] calculation, at random, eliminating the possibility of a tie. Kind of a hack but it should work.

Hope it helps!

Upvotes: 1

ainsighta
ainsighta

Reputation: 98

Create a measure called rank:

Rank = RANKX ( ALLSELECTED ( Table1[emp name] ), CALCULATE ( SUM ( Table1[mark] ) ) )

Table with rank measure

Click on the table, go into 'Visual level filters' find the rank column and set a condition that shows items when the value is less than 3:

enter image description here

That will give you this:

enter image description here

Upvotes: 3

Related Questions