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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
SleveMcDichael
New Member

Coloring top N in a bar chart with legend or conditional formatting

Hi all!


I'm running into an issue that really stumps me. I want to differentiate the top 5 bars in a bar chart by giving them a different color and I keep running into a wall. It has to be done using a measure as the top 5's need to change when filtering.


I've been trying to write a measure with the TOPN dax function that can either be inserted as a legend or as a field value in conditional formatting, but I can't get the syntax right.


Not omitting an example due to laziness - I just had nothing worth posting ‌😅

 

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your datamodel.

 

Jihwan_Kim_0-1673629815541.png

 

Jihwan_Kim_1-1673630476312.png

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

v-zhangti
Community Support
Community Support

Hi, @SleveMcDichael 

 

You can try the following methods.
Measure:

Rank = RANKX(ALL('Table'),CALCULATE(SUM('Table'[Value])),,DESC)

vzhangti_1-1673851242393.png

Color = IF([Rank]<=5,"Green")

vzhangti_2-1673851320522.png

Result:

vzhangti_3-1673851342379.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

 

View solution in original post

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @SleveMcDichael 

 

You can try the following methods.
Measure:

Rank = RANKX(ALL('Table'),CALCULATE(SUM('Table'[Value])),,DESC)

vzhangti_1-1673851242393.png

Color = IF([Rank]<=5,"Green")

vzhangti_2-1673851320522.png

Result:

vzhangti_3-1673851342379.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

 

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your datamodel.

 

Jihwan_Kim_0-1673629815541.png

 

Jihwan_Kim_1-1673630476312.png

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

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.