Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

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

  • Anonymous,

     

    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:

     

     

    Use DimGroup[Group] in a visual:

     

     

1 Reply

  • Anonymous,

     

    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:

     

     

    Use DimGroup[Group] in a visual: