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.
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:
Customer | Region | Sales |
A | INT | 10 |
B | INT | 20 |
C | INT | 30 |
D | INT | 40 |
E | INT | 50 |
F | INT | 60 |
G | INT | 70 |
A | AMER | 80 |
B | AMER | 90 |
C | AMER | 100 |
D | AMER | 110 |
E | AMER | 120 |
F | AMER | 130 |
G | AMER | 140 |
A | AMER | 150 |
B | AMER | 160 |
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
Customer | Region | Sales |
B | AMER | 160 |
A | AMER | 150 |
G | AMER | 140 |
F | AMER | 130 |
E | AMER | 120 |
G | INT | 70 |
F | INT | 60 |
E | INT | 50 |
D | INT | 40 |
C | INT | 30 |
Thank you!
Solved! Go to Solution.
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:
Be aware that the table visual is sorted by two columns (Sort by more than one column in Power BI - YouTube)
Hopefully, this provides what you are looking for
Regards,
Tom
Simple enough,
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! |
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:
Be aware that the table visual is sorted by two columns (Sort by more than one column in Power BI - YouTube)
Hopefully, this provides what you are looking for
Regards,
Tom
Hey @Anonymous ,
does this provide what you are looking for: Solved: Ranking within a group - Microsoft Power BI Community
Regards,
Tom
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
95 | |
80 | |
68 | |
59 |
User | Count |
---|---|
150 | |
119 | |
104 | |
87 | |
67 |