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

Why is this RANKX not working?

I have data as per below:

Attribute CategorySectionAttributePointsMax Points
AttributeSection 1Question 11790.001820.00
AttributeSection 2Question 21315.001455.00
AttributeSection 2Question 32610.002950.00
AttributeSection 3Question 42015.002080.00
AttributeSection 3Question 52925.002950.00
AttributeSection 4Question 62845.002930.00
AttributeSection 4Question 74395.004910.00
AttributeSection 4Question 8785.00810.00
AttributeSection 4Question 91890.001980.00
AttributeSection 4Question 101104.001122.00
AttributeSection 4Question 111882.501945.00
AttributeSection 5Question 12507.50545.00
AttributeSection 5Question 132267.502405.00
AttributeSection 5Question 142640.002745.00
AttributeSection 5Question 152547.502950.00
AttributeSection 5Question 165000.005820.00
AttributeSection 5Question 171295.001410.00
AttributeSection 6Question 189840.0011800.00
AttributeSection 6Question 19960.001095.00
AttributeSection 6Question 20400.00480.00
AttributeSection 6Question 21132.50155.00
AttributeSection 7Question 22352.50425.00
AttributeSection 7Question 231685.001980.00
AttributeSection 8Question 241975.002420.00
MasterTotal ResultTotal Result  
SectionSection 1 1790.001820.00
SectionSection 2 3802.504405.00
SectionSection 3 4885.005030.00
SectionSection 4 12901.5013697.00
SectionSection 5 13912.5015875.00
SectionSection 6 11267.5013530.00
SectionSection 7 2037.502405.00
SectionSection 8 1975.002420.00

 

and a measure to calculate pass rate:

(%) Pass Rate = iferror(sum('QA Data'[Points])/sum('QA Data'[Max Points]),BLANK())

 

 

 

Now, I can display a simple table visual with the Pass Rate per Attribute (with a visual filter on Attribute Category = Attribute) and a table visual with the Pass Rate per Section (with a visual filter on Attribute Category = Section).

 

Now, I need to color-code the top 5 and bottom 5 attributes. After searching the web, the best approach seems to be to create a rank measure, and then look at rank 1 through 5 for the top 5, and rank 19 through 24 for the bottom 5 (cause there are 24 arrtibutes).

 

However, every different RANKX approch I have used so far results in either rank 1 for all attributes, or rank with very high numbers (matches rows of data, example the highest pass rate has rank 1, then the next attribute has rank 388 meaning there are 387 rows for the same attribute that got rank 1).

 

All I need is a rank 1 through 24. What am I doing wrong?

1 ACCEPTED SOLUTION
Remco1986
Helper I
Helper I

After some troubleshooting, I have found the solution. Let me explain:

I have a 2nd table with the sortOrder of the questions. In my main data, I have added the sortorder using the RELATED() function. I then sorted the Attribute text by the sortOrder.

 

This is what broke the RANKX. All I needed to do was to include the sortOrder in the RANKX function.

 

So this: 

 

RANKX(all('QA Data'[Attribute]),calculate(sum('QA Data'[Points])/sum('QA Data'[Max Points])),,DESC,dense)

 

 

Should be changed to this:

 

RANKX(all('QA Data'[Attribute],'QA Data'[sortAttribute]),calculate(sum('QA Data'[Points])/sum('QA Data'[Max Points])),,DESC,dense)

 

Or shorter, I could use the Pass Rate measure instead of the CALCULATE(SUM()/SUM())

 

RANKX(all('QA Data'[Attribute],'QA Data'[sortAttribute]),[(%) Pass Rate],,DESC,dense)

 

 

View solution in original post

1 REPLY 1
Remco1986
Helper I
Helper I

After some troubleshooting, I have found the solution. Let me explain:

I have a 2nd table with the sortOrder of the questions. In my main data, I have added the sortorder using the RELATED() function. I then sorted the Attribute text by the sortOrder.

 

This is what broke the RANKX. All I needed to do was to include the sortOrder in the RANKX function.

 

So this: 

 

RANKX(all('QA Data'[Attribute]),calculate(sum('QA Data'[Points])/sum('QA Data'[Max Points])),,DESC,dense)

 

 

Should be changed to this:

 

RANKX(all('QA Data'[Attribute],'QA Data'[sortAttribute]),calculate(sum('QA Data'[Points])/sum('QA Data'[Max Points])),,DESC,dense)

 

Or shorter, I could use the Pass Rate measure instead of the CALCULATE(SUM()/SUM())

 

RANKX(all('QA Data'[Attribute],'QA Data'[sortAttribute]),[(%) Pass Rate],,DESC,dense)

 

 

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.

Top Solution Authors