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
logrt
Frequent Visitor

RANKX based on two numerical columns and grouped

Hi there, hope you can help me with this:

 

I have the following table, with a set of equipments that belongs to different fleets:

 

EquipStopsHoursFleet
A46X
B35X
C24X
D43X
E31Y
F42Y
G45Y
H36Z
I22Z
J43Z

 

I want to rank these equipments first by stops and then by hours, according to each fleet, like this:

 

EquipStopsHoursFleetRANK
A46X1
B35X3
C24X4
D43X2
E31Y3
F42Y2
G45Y1
H36Z2
I22Z3
J43Z1

 

Also i want a measure that returns me the equip that ranks 2nd in every fleet, is that possible?

 

I am still learning with Power Bi and DAX functions

Regards

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hello @logrt

Create the following classification measure:

Rank = 
RANKX (
    FILTER (
        ALLSELECTED ( 'Table'[Fleet]; 'Table'[Equip]; 'Table'[Hours]; 'Table'[Stops] );
        'Table'[Fleet] = SELECTEDVALUE ( 'Table'[Fleet] )
    );
    CALCULATE ( SUM ( 'Table'[Stops] ) + SUM ( 'Table'[Hours] ) / 10000 )
)

By having the Total Hours divided by 10000 to make a small decimal that changes the order if only d.o the sum of stop and hours has to be you would not get the tiebreaker.

For second classification you can use the above measurement and filter the display by classification 2


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

1 REPLY 1
MFelix
Super User
Super User

Hello @logrt

Create the following classification measure:

Rank = 
RANKX (
    FILTER (
        ALLSELECTED ( 'Table'[Fleet]; 'Table'[Equip]; 'Table'[Hours]; 'Table'[Stops] );
        'Table'[Fleet] = SELECTEDVALUE ( 'Table'[Fleet] )
    );
    CALCULATE ( SUM ( 'Table'[Stops] ) + SUM ( 'Table'[Hours] ) / 10000 )
)

By having the Total Hours divided by 10000 to make a small decimal that changes the order if only d.o the sum of stop and hours has to be you would not get the tiebreaker.

For second classification you can use the above measurement and filter the display by classification 2


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.