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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Syndicate_Admin
Administrator
Administrator

Top 5 Bar Chart Comparison

Hello People 😁

I am writing to you because of a doubt I have.

Is there a way to create a bar or line graph in which I show the top 5 and not be a product of a certain classification that takes the top 5 and replaces it with that particular product?

Thank you very much in advance for answering, and sorry if I wrote something very odvio or unclear.

Someone can help me 😭

3 REPLIES 3
Anonymous
Not applicable

Hi @Syndicate_Admin ,

 

If you want to replace it to a specific product, you need to replace it in Power Query.

According to your description, here are my steps you can follow as a solution.

(1) This is my test data.  

vtangjiemsft_0-1673493564781.png

(2) Click "Advanced Editor", paste the following code, and then click "Close and Apply". You can also refer to the steps on the right side of the following PBIX.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSsrMTlXSUUoEYiMDpVidaKWCjPw8kFASEBtDhMoTS5IzoEImEKGSMijfFKorNQ/ISQZiM4hAUWlOahFUyBwoFAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, #"type" = _t, sale = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"type", type text}, {"sale", Int64.Type}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"sale", Order.Descending}}),
    #"Kept Range of Rows" = Table.Range(#"Sorted Rows",0,5),
    #"Replaced Value" = Table.ReplaceValue(#"Kept Range of Rows","ruler","new_top1",Replacer.ReplaceText,{"Product"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","pen","new_top2",Replacer.ReplaceText,{"Product"}),
    #"Replaced Value2" = Table.ReplaceValue(#"Replaced Value1","tv","new_top3",Replacer.ReplaceText,{"Product"}),
    #"Replaced Value3" = Table.ReplaceValue(#"Replaced Value2","watch","new_top4",Replacer.ReplaceText,{"Product"}),
    #"Replaced Value4" = Table.ReplaceValue(#"Replaced Value3","phone","new_top5",Replacer.ReplaceText,{"Product"})
in
    #"Replaced Value4"

(3) Then the result is as follows.

vtangjiemsft_0-1673501543798.png

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

Thanks for replying! 😄 I understand what you're saying, but doing that would replace the data in a flat table, right? 😞 Part of the problem is that I need it to be dynamic, that is.

I have a market with different participants, which includes several products of the company for which I work, the problem is that when I select with a filter a market segmentation I can visualize the product of the company next to the top 5 regardless of whether or not the product is in top 5. Attached is an example of the problem

BD Test

amitchandak
Super User
Super User

@Syndicate_Admin , Use TOPN filter at the visual level

 

TOPN: https://youtu.be/QIVEFp-QiOk

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.