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
danielgergely
Advocate II
Advocate II

RANKX not functioning properly

Hey everyone

 

I have an interesting situation. 

I have a list of customers with sales. I want to rank them by sales and make a comparison between the first X by sales and the rest of the customers. 
Here is the Table with the three measures (Rank_Kunde, Rank_Kunde2, Rank_Kunde4)

ice_screenshot_20200915-082637.png

As you can see, the sorting is really wierd. Skipping some numbers and at the same time sorting incorrectly.

 
 

Inorder to keep the list dynamic and filterable, I created multiple measures.

Measure 1 (Rank_Kunde): 

 

 

 

 

Rank_Kunde = 
VAR _kunde =  SELECTEDVALUE(Table[Kunde_])
VAR _sum = CALCULATE(SUM(Table[Nettoerlös]),FILTER(ALLSELECTED(Table),Table[Kunde_]=_kunde))
RETURN _sum

 

 

 

 

 
Measure 2 (Rank_Kunde2):

 

 

 

Rank_Kunde2 = RANKX(ALLSELECTED(Table), CALCULATE([Rank_Kunde]),,DESC,Dense)

 

 

 

Measure 3 (Rank_Kunde4) is quite long, and irrelevant, but ill post in anyway:

 

 

Rank_Kunde4 = 
VAR _top =  SELECTEDVALUE(TOPX[Top])
VAR _first = RANKX(ALLSELECTED(KE30_KPI), CALCULATE([Rank_Kunde]),,DESC,Dense)
VAR _kunde = SELECTEDVALUE(KE30_KPI[Kunde_])
VAR _one = CALCULATE(FIRSTNONBLANK(TOPKunden[Kunde_],1),FILTER(ALL(TOPKunden),TOPKunden[Rank] = 1))
VAR _two = CALCULATE(FIRSTNONBLANK(TOPKunden[Kunde_],1),FILTER(ALL(TOPKunden),TOPKunden[Rank] = 2))
VAR _three = CALCULATE(FIRSTNONBLANK(TOPKunden[Kunde_],1),FILTER(ALL(TOPKunden),TOPKunden[Rank] = 3))
VAR _four = CALCULATE(FIRSTNONBLANK(TOPKunden[Kunde_],1),FILTER(ALL(TOPKunden),TOPKunden[Rank] = 4))
VAR _five = CALCULATE(FIRSTNONBLANK(TOPKunden[Kunde_],1),FILTER(ALL(TOPKunden),TOPKunden[Rank] = 5))
VAR _six = CALCULATE(FIRSTNONBLANK(TOPKunden[Kunde_],1),FILTER(ALL(TOPKunden),TOPKunden[Rank] = 6))
VAR _seven = CALCULATE(FIRSTNONBLANK(TOPKunden[Kunde_],1),FILTER(ALL(TOPKunden),TOPKunden[Rank] = 7))
VAR _eight = CALCULATE(FIRSTNONBLANK(TOPKunden[Kunde_],1),FILTER(ALL(TOPKunden),TOPKunden[Rank] = 8))
VAR _nine = CALCULATE(FIRSTNONBLANK(TOPKunden[Kunde_],1),FILTER(ALL(TOPKunden),TOPKunden[Rank] = 9))
VAR _ten = CALCULATE(FIRSTNONBLANK(TOPKunden[Kunde_],1),FILTER(ALL(TOPKunden),TOPKunden[Rank] = 10))

VAR _result10 = SWITCH(_first, 1, _one, 2, _two, 3, _three, 4, _four, 5, _five, 6, _six, 7, _seven, 8, _eight, 9, _nine, 10, _ten, "Übrige Kunden")
VAR _result9 = SWITCH(_first, 1, _one, 2, _two, 3, _three, 4, _four, 5, _five, 6, _six, 7, _seven, 8, _eight, 9, _nine, "Übrige Kunden")
VAR _result8 = SWITCH(_first, 1, _one, 2, _two, 3, _three, 4, _four, 5, _five, 6, _six, 7, _seven, 8, _eight, "Übrige Kunden")
VAR _result7 = SWITCH(_first, 1, _one, 2, _two, 3, _three, 4, _four, 5, _five, 6, _six, 7, _seven, "Übrige Kunden")
VAR _result6 = SWITCH(_first, 1, _one, 2, _two, 3, _three, 4, _four, 5, _five, 6, _six, "Übrige Kunden")
VAR _result5 = SWITCH(_first, 1, _one, 2, _two, 3, _three, 4, _four, 5, _five, "Übrige Kunden")
VAR _result4 = SWITCH(_first, 1, _one, 2, _two, 3, _three, 4, _four, "Übrige Kunden")
VAR _result3 = SWITCH(_first, 1, _one, 2, _two, 3, _three, "Übrige Kunden")
VAR _result2 = SWITCH(_first, 1, _one, 2, _two, "Übrige Kunden")
VAR _result1 = SWITCH(_first, 1, _one, "Übrige Kunden")
VAR _topXResult = SWITCH(_top, 1, _result1, 2, _result2, 3, _result3, 4, _result4, 5, _result5, 6, _result6, 7, _result7, 8, _result8, 9, _result9, 10, _result10)
RETURN _topXResult<span><br />Could anyone explain why my RANKX is not working?<br /><div> <div><span>Thank you<div><span>Daniel</span></div></span></div></div></span>

 

 

 

Does anyone know where I might have made a mistake or why RANKX is not functioning?

 

Thank you

Daniel

 

1 ACCEPTED SOLUTION
danielgergely
Advocate II
Advocate II

So after a lot of experimentation, i discovered that if i filter the visual and take 1 of the values out, then RANKX() works properly...

Really wierd...

I guess it is a bug or something...

 

If anyone comes up with an explanation or something, then I'll accept it as a sollution

View solution in original post

2 REPLIES 2
danielgergely
Advocate II
Advocate II

So after a lot of experimentation, i discovered that if i filter the visual and take 1 of the values out, then RANKX() works properly...

Really wierd...

I guess it is a bug or something...

 

If anyone comes up with an explanation or something, then I'll accept it as a sollution

amitchandak
Super User
Super User

@danielgergely , Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

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.