Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
Anonymous
Not applicable

adding legend to my bar chart breaks top N

So right now, i have a bar chart, a dropdown for top N, field parameters for the aggregated value and legend (seen in the first image).

 

rasberryPie_0-1697184792970.png

 

Without adding legends, the top N works fine. But once I add a legend into the Legends field of the bar chart, the top N breaks. In this example, I selected top 5 bars. After adding the legend, it shows more than 5 bars.

 

rasberryPie_1-1697184905229.png

 

I created 3 parameters:

- value_filter: contains the aggregation values (ie agg1, agg2)

- legend_filter: contains the aggregation values (ie legend1, legend2)

- top: a series from 1 to 10

 

I created 2 measures,
- "rank": sort the bars by the selected aggregated value. 

- "topN": show the top N values

 

Below are the DAX codes for my measures

 

rank =
SWITCH(
    TRUE(),
    SELECTEDVALUE(value_filter[Parameter Fields])="'table'[agg1]",
    RANKX(
        ALL(table[Alias]),
        [agg1],,
        DESC
    ),
    SELECTEDVALUE(value_filter[Parameter Fields])="'table'[agg2]",
    RANKX(
        ALL(table[Alias]),
        [agg2],,
        DESC
    )
)
 
topN =
var _selectedNumber = SELECTEDVALUE('top'[top])
return
INT(
    [rank]<=_selectedNumber
)
 
I would greatly appreciate any and all suggestions!
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

You can consider using a purely graphical solution. The filter pane already has a TOPN filter premade for you.

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

You can consider using a purely graphical solution. The filter pane already has a TOPN filter premade for you.

Anonymous
Not applicable

but if i use the filter pane and set top N by agg1,the top N wouldn't change when I use the parameter filter to change to agg2

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors