Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Advanced RANKX Question

Hello, mates!

 

I have the following question that I have no idea what can I do:

 

I have a table called 'Sections' with this columns: 

  • ID: code of a bus line
  • FROM: start place 
  • TO: finish place
  • DISTANCE
  • WAY

And for each ID and WAY I must rank this line IDs, ordering the sections based on distance between FROM and TO.

 

An exemple:

SECTIONS TABLE
IDFROMTODISTANCEWAY
1AB10going
1AC25going
1AD42going
1BC15going
1BD32going
1CD17going
2RS50going
2RT70going
2ST20going
1DA42return
1DB32return
1DC17return
1CA25return
1CB15return
1BA10return
2TR70return
2TS20return
2SR50return

 

My expect result:

RANKED SECTIONS
IDSECCIONWAYRANK
1Agoing1
1Bgoing2
1Cgoing3
1Dgoing4
1Dreturn1
1Creturn2
1Breturn3
1Areturn4
2Rgoing1
2Sgoing2
2Tgoing3
2Treturn1
2Rreturn2
2Sreturn3

 

Please help me! 😞

🙂

1 ACCEPTED SOLUTION
tex628
Community Champion
Community Champion

Try this:

Rank X 2 = 
VAR Filt = SELECTEDVALUE(Table2[Filter])
Return
RANKX ( FILTER(ALL ( Table2 );Table2[Filter]=Filt); [Dist] )

Table2[Filter] is a calculated column:

Filter = Table2[ID] & Table2[Way]

[Dist] is a measure:

Dist = SUM(Table2[Distance])
 

Connect on LinkedIn

View solution in original post

4 REPLIES 4
tex628
Community Champion
Community Champion

Try this: 

Rank X = 
VAR Val = Table2[ID]
VAR Val2 = Table2[Way]
Return
RANKX(FILTER(Table2;Table2[ID]=Val && Table2[Way] = Val2); Table2[Distance])

Connect on LinkedIn
Anonymous
Not applicable

I am not able to set a table[column] as a VAR

tex628
Community Champion
Community Champion

Try this:

Rank X 2 = 
VAR Filt = SELECTEDVALUE(Table2[Filter])
Return
RANKX ( FILTER(ALL ( Table2 );Table2[Filter]=Filt); [Dist] )

Table2[Filter] is a calculated column:

Filter = Table2[ID] & Table2[Way]

[Dist] is a measure:

Dist = SUM(Table2[Distance])
 

Connect on LinkedIn
tex628
Community Champion
Community Champion

Ohh, you are making a measure and not a calculated column? 

Un momento!


Connect on LinkedIn

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors