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
Asamadi
Helper I
Helper I

Dynamic TopN & Ranking in Power BI

How may i create a Table  ( Matrix) like the below image, This is my Excel Sample Data: https://www.dropbox.com/s/ndg0t0tfpn4bt6d/001.xlsx?dl=0

Untitled2.png

2 ACCEPTED SOLUTIONS
erik_tarnvik
Solution Specialist
Solution Specialist

 

I would first use the query editor to transform your input data so you have only one score per line in your TestData table. Mark the four score columns and use "Unpivot columns", rename the resulting Attribute/Value columns to get this:

 

image.png

 

Then define two measures:

AverageScore = AVERAGE(TestData[Test Score])

StudentRank = RANKX(ALL(TestData[Name],TestData[Topic]), Calculate(Average(TestData[Test Score]),ALLEXCEPT(TestData,TestData[Name],TestData[Topic])),,DESC,Skip)

 

Populate a table visual with Topic, Name, AverageScore and StudentRank and define a visual filter on StudentRank to only show value less or equal to 5. Result:

 

image.png

 

Now, obviously this is 6 values but given the subject matter I assume you don't want to leave tied students out of the top 5.

 

I am sure there are better solutions, I am not a guru and would love to learn more myself!

View solution in original post

v-yuezhe-msft
Employee
Employee

@Asamadi,

In addition to other’s result, to display the bottom  5 performance performing employees, create the following measure. Then drag the measure to your Matrix visual and set its values to “less than or equal to 5”.

rank2 = RANKX(ALL(TestData[Name],TestData[Topic]), Calculate(Average(TestData[Test Score]),ALLEXCEPT(TestData,TestData[Name],TestData[Topic])),,ASC,Skip)

Besides, when creating the Matrix visual, turn off “Stepped layout” option under Row headers and drill down to the lowest level, you will get expected result.
1.JPG

 

Regards,
Lydia

Community Support Team _ Lydia Zhang
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

4 REPLIES 4
v-yuezhe-msft
Employee
Employee

@Asamadi,

In addition to other’s result, to display the bottom  5 performance performing employees, create the following measure. Then drag the measure to your Matrix visual and set its values to “less than or equal to 5”.

rank2 = RANKX(ALL(TestData[Name],TestData[Topic]), Calculate(Average(TestData[Test Score]),ALLEXCEPT(TestData,TestData[Name],TestData[Topic])),,ASC,Skip)

Besides, when creating the Matrix visual, turn off “Stepped layout” option under Row headers and drill down to the lowest level, you will get expected result.
1.JPG

 

Regards,
Lydia

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

Hello thanks for your response

may you send me the pbix file?

my email:

akbar.samadi110@gmail.com

@Asamadi,

You can download the PBIX file from the following link.
https://1drv.ms/u/s!AhsotbnGu1Nogn5wQ3lO61iwIpAz

Regards,
Lydia

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

 

I would first use the query editor to transform your input data so you have only one score per line in your TestData table. Mark the four score columns and use "Unpivot columns", rename the resulting Attribute/Value columns to get this:

 

image.png

 

Then define two measures:

AverageScore = AVERAGE(TestData[Test Score])

StudentRank = RANKX(ALL(TestData[Name],TestData[Topic]), Calculate(Average(TestData[Test Score]),ALLEXCEPT(TestData,TestData[Name],TestData[Topic])),,DESC,Skip)

 

Populate a table visual with Topic, Name, AverageScore and StudentRank and define a visual filter on StudentRank to only show value less or equal to 5. Result:

 

image.png

 

Now, obviously this is 6 values but given the subject matter I assume you don't want to leave tied students out of the top 5.

 

I am sure there are better solutions, I am not a guru and would love to learn more myself!

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.