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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
wookietreiber
Frequent Visitor

How to Limit Displayed Labels in a Power BI Bar Chart Visual?

Hello Power BI Community,

I'm currently working on a bar chart in Power BI and facing a unique challenge. I wish to display all the bars in my chart, but I only want to label the top three bars based on their value. Is there a way to customize the chart to show labels only for these specific bars?

I think that Power BI doesn’t have a direct setting for this exact requirement. However, I am open to creative solutions or workarounds. Here’s what I am trying to achieve:

  • Display all bars: All bars in the chart should be visible.
  • Limit labels to top three: Only the first three bars (by value) should have labels displaying their values.

I believe this might involve creating a custom measure using DAX, but I am not entirely sure how to structure this measure to conditionally display labels only for the top three bars. Any guidance on how to approach this, or alternative suggestions, would be greatly appreciated.

 

Thank you in advance for your help!

 

Best

Chris

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@wookietreiber,

 

This example uses a star schema (dimension and fact tables with a one-to-many relationship) and these measures:

 

Amount = SUM ( FactTable[Amount] )
Data Label Formatting = 
VAR vSourceTable =
    ADDCOLUMNS ( ALLSELECTED ( DimGroup[Group] ), "@Amount", [Amount] )
VAR vRank =
    RANK ( DENSE, vSourceTable, ORDERBY ( [@Amount], DESC, DimGroup[Group] ) )
VAR vResult =
    // if rank is greater than 3, set data label color to match the background so it's invisible
    IF ( vRank > 3, "#FFFFFF" )
RETURN
    vResult

 

Set conditional formatting for the data labels color using the Data Label Formatting measure:

 

DataInsights_0-1705334285621.png

 

Use DimGroup[Group] in a visual:

 

DataInsights_1-1705334318105.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
DataInsights
Super User
Super User

@wookietreiber,

 

This example uses a star schema (dimension and fact tables with a one-to-many relationship) and these measures:

 

Amount = SUM ( FactTable[Amount] )
Data Label Formatting = 
VAR vSourceTable =
    ADDCOLUMNS ( ALLSELECTED ( DimGroup[Group] ), "@Amount", [Amount] )
VAR vRank =
    RANK ( DENSE, vSourceTable, ORDERBY ( [@Amount], DESC, DimGroup[Group] ) )
VAR vResult =
    // if rank is greater than 3, set data label color to match the background so it's invisible
    IF ( vRank > 3, "#FFFFFF" )
RETURN
    vResult

 

Set conditional formatting for the data labels color using the Data Label Formatting measure:

 

DataInsights_0-1705334285621.png

 

Use DimGroup[Group] in a visual:

 

DataInsights_1-1705334318105.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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