Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Link to pbix: Dynamic TopN with Legend not working.pbix
In my sample, I have a horizontal stacked bar chart (Sales by City) that interacts correctly with the dynamic Top N parameter:
I used the following rank measure:
All is well until adding a sub-category as a legend breaks the dynamic top N:
How do I make sure the chart still displays the correct number of cities even with a sub-category applied as a legend? I have attached a link to the sample pbix. Thank you!
@Anonymous , Try updating measure as
Rank_City =
RANKX(
ALLSELECTED('Dim_City'[City], 'Dim_SubCategory'[SubCategory]),
[Sales Amount],
,
DESC,
DENSE
)
And
TopNCity =
IF(
[Rank_City] <= 'TopN'[TopN Value],
1,
0
)
Ensure that the TopNCity measure is applied as a visual-level filter on your chart, and set it to show only values where TopNCity equals 1.
Proud to be a Super User! |
|
Hi @bhanu_gautam,
It didn't work as it says that columns used in ALLSELECTED must be from the same table:
But thank you for the idea because from there, I tried to create a table that summarizes the City and Sub-Category, established a many-to-many relationship with the fact table. I used these columns in the chart and updated the rank measure as well: