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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! 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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.