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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.