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

Return nth ranked value based on criteria

In the below dataset I have a column that ranks the order/position of a value within a grouping. I'm trying to find a dax function that will allow me to return the nth largest value based within a given [Address] using the [Rank] value to identify what [SwapRank] to return. Below is a sample data set that includes what the returned values would be including comments/notes to clarify my thoughts.

 

AddressSuiteRankSwapRankThoughts/Notes
Address 110015<- Returns nth largest "rank" based on "address" criteria for each address in dataset
Address 112015
Address 120024
Address 130033<- Can it somehow be simplified by utilizing the "Rank" as the nth heighest position, thus it would return the swapped value?
Address 132033
Address 140042
Address 150051 
Address 210014Returns "4" because it is the "1st" largest number based on the Address 2 criteria
Address 215014 
Address 220023Returns "3" because it is the "2nd" largest number based on the Address 2 criteria
Address 230032 
Address 233032 
Address 240041 
1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @CREsearch ,

Try this:

SwapRank 2 = 
RANKX (
    FILTER ( 'Table', 'Table'[Address] = EARLIER ( 'Table'[Address] ) ),
    'Table'[Rank],
    ,
    DESC,
    DENSE
)

rankcol.PNG

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

Try these measure

Rank value = MIN(Data[Rank])
Reverse rank = RANKX(ALLEXCEPT(Data,Data[Address]),[Rank value],,DESC,dense)

To your visual drag the second measure.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Icey
Community Support
Community Support

Hi @CREsearch ,

If so, just try this:

Create a measure:

SwapRank = 
RANKX (
    ALLEXCEPT ( 'Table', 'Table'[Address] ),
    CALCULATE ( MAX ( 'Table'[Rank] ) ),
    ,
    DESC,
    DENSE
)

swap.PNG

 

Best Regards
Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I'm getting a circular dependency error for some reason. Note that it has to be a custom column I believe and not a measure as I need to use it for an axis in a bar chart. 

Icey
Community Support
Community Support

Hi @CREsearch ,

Try this:

SwapRank 2 = 
RANKX (
    FILTER ( 'Table', 'Table'[Address] = EARLIER ( 'Table'[Address] ) ),
    'Table'[Rank],
    ,
    DESC,
    DENSE
)

rankcol.PNG

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Yes, works like a charm! Thank you!

Hi,

If my reply helped, please mark it as Answer.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Icey
Community Support
Community Support

Hi @CREsearch ,

How do you calculate the “Rank” column? Is the “SwapRank” column a reverse sort of the “Rank” column?

 

Best Regards,

Icey

The Rank field is provided. And yes - it’s essentially a reverse sort in a way!

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.