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
Anonymous
Not applicable

Nested Ranking based off 2 value

Hi all,

 

I am trying to create a visual level filter to show the top 5 in one region then top 5 in another region then sort the result by the value. 

 

For example I have table visaul that looks like this:

CustomerRegionSales
AINT10
BINT20
CINT30
DINT40
EINT50
FINT60
GINT70
AAMER80
BAMER90
CAMER100
DAMER110
EAMER120
FAMER130
GAMER140
AAMER150
BAMER160

 

The desrired outcome would look like this:
I initally did the ranking in PQ but I face issues when adding filters on the page for the user

 

CustomerRegionSales
BAMER160
AAMER150
GAMER140
FAMER130
EAMER120
GINT70
FINT60
EINT50
DINT40
CINT30

 

Thank you!

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey @Anonymous ,

 

next to the approach from the linked thread this measure usually performs better:

Measure 2 = 
var currentRegion = CALCULATE( FIRSTNONBLANK( 'Table (2)'[Region] , 'Table (2)'[Region] ) )
var currentSales = CALCULATE( SUM( 'Table (2)'[Sales] ) )
var rankCountrows = 
COUNTROWS(
    FILTER(
        ALLSELECTED( 'Table (2)' )
        ,  'Table (2)'[Region] = currentRegion && 'Table (2)'[Sales] >= currentSales
    )
)
return
IF(
    rankCountrows <= 5
    , rankCountrows
    , BLANK()
)

It allows to create this table visual:

image.png

Be aware that the table visual is sorted by two columns (Sort by more than one column in Power BI - YouTube)

  1. region
  2. Measure 2

Hopefully, this provides what you are looking for

 

Regards,

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

4 REPLIES 4
CNENFRNL
Community Champion
Community Champion

Simple enough,

CNENFRNL_0-1655781691983.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

TomMartens
Super User
Super User

Hey @Anonymous ,

 

next to the approach from the linked thread this measure usually performs better:

Measure 2 = 
var currentRegion = CALCULATE( FIRSTNONBLANK( 'Table (2)'[Region] , 'Table (2)'[Region] ) )
var currentSales = CALCULATE( SUM( 'Table (2)'[Sales] ) )
var rankCountrows = 
COUNTROWS(
    FILTER(
        ALLSELECTED( 'Table (2)' )
        ,  'Table (2)'[Region] = currentRegion && 'Table (2)'[Sales] >= currentSales
    )
)
return
IF(
    rankCountrows <= 5
    , rankCountrows
    , BLANK()
)

It allows to create this table visual:

image.png

Be aware that the table visual is sorted by two columns (Sort by more than one column in Power BI - YouTube)

  1. region
  2. Measure 2

Hopefully, this provides what you are looking for

 

Regards,

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

@TomMartens perfect, thank you for the help!!!!!

TomMartens
Super User
Super User

Hey @Anonymous ,

 

does this provide what you are looking for: Solved: Ranking within a group - Microsoft Power BI Community

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

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.