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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! 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
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

Top Kudoed Authors