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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Nyakwezi
Frequent Visitor

Dynamic Number of Bars in a Bar Chart

Hi all,

I have a bar chart visual with multiple categories (e.g. customer names) on the Y axis and Revenue generated from each customer on the X axis. These customers are ranked based on the Revenue generated from them

I also have a customer slicer on this tab - so when one customer is selected on this slicer, the bar chart shows a comparison of this customer with the other customers.

I would like to be able to only show a few bars depending on the customer selected.

 

e.g. 

if customer selected has a rank of 10, then in the bar graph only show me customers who are ranked from 1 - 15 OR if the customer selected has a rank of 11, then the bar graph should only show me customers who are ranked from 1 - 16.

 

I'm doing this to reduce the overcrowded bar graph because I am dealing with about 30 customers and I don't want them to all appear in my categories

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Nyakwezi ,

first please create a new table for the slicer:

vcgaomsft_0-1704943853871.png

And then please create 2 measures like:

Ranking = RANKX(ALL('Table'[Customer ID]),[Total Profit],,DESC,Dense)
ViusalsFilter = 
VAR _select_id = SELECTEDVALUE('DimCustomer'[Customer ID])
VAR _select_rank = IF( NOT ISBLANK(_select_id), CALCULATE([Ranking],'Table'[Customer ID]=_select_id))
VAR _max_rank = _select_rank+5
VAR _filter = 
IF(ISBLANK(_select_id),1,IF([Ranking]<=_max_rank,1))
RETURN
_filter

Apply the 2nd measure to the bar charts filter:

vcgaomsft_1-1704943943643.png

And the output:

vcgaomsft_2-1704943972957.png

Please check the pbix file.

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Nyakwezi ,

first please create a new table for the slicer:

vcgaomsft_0-1704943853871.png

And then please create 2 measures like:

Ranking = RANKX(ALL('Table'[Customer ID]),[Total Profit],,DESC,Dense)
ViusalsFilter = 
VAR _select_id = SELECTEDVALUE('DimCustomer'[Customer ID])
VAR _select_rank = IF( NOT ISBLANK(_select_id), CALCULATE([Ranking],'Table'[Customer ID]=_select_id))
VAR _max_rank = _select_rank+5
VAR _filter = 
IF(ISBLANK(_select_id),1,IF([Ranking]<=_max_rank,1))
RETURN
_filter

Apply the 2nd measure to the bar charts filter:

vcgaomsft_1-1704943943643.png

And the output:

vcgaomsft_2-1704943972957.png

Please check the pbix file.

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

Oh my word.
Thank you so much.

I've been at this for a couple of months. It worked perfectly

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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