Forum Discussion

MateuszW's avatar
MateuszW
New Member
8 months ago
Solved

Hiding blank Legend elemants

Hello,

I'm a new PowerBi user. I'm making a Stacked Area Chart supposed to show different categories of traffic at different locations. The problem is that some categories apply only to certain locations. The graph itself changes fine, according to location but the Legend keeps showing all categories, including those unused.

 

Like below, where only four out of nine categories are applicable:

 

Is there a way to get rid of extra elements?

TY

MW

  • Hi MateuszW

    Because the legends are measures, applying an “is not blank” visual filter (if one is used) can produce misleading results. For example, if the first measure evaluates to blank for a given data point, the remaining measures for that same point will also return blank, even if they should logically have values.

     

    The practical workaround is to disable the built-in legend and instead use a visual that mimics the legend. Two common approaches:

    • DAX-generated SVG legend. Create an SVG image in DAX that displays the legend color and label. This works visually, but since it is a single image, the legend items are not clickable.
    • Circle SVG + button/tile slicer. Use a small DAX-generated circle SVG as the icon in a button or tile slicer and format it to look like a legend.

    Note:

    For both approaches, a disconnected table is required that lists the measure or metric names along with their corresponding colors. A measure should be created to return the appropriate value based on the metric name column.

    In the second approach, the button slicer remains clickable, but it will not filter the line chart unless the measure described above is used within the visual.

     

    Please see the attached sample pbix.

4 Replies

  • Option 1: Make the measure return BLANK()

    Ensure your measure truly returns BLANK() (not 0) when the category doesn’t apply.

    Traffic =
    VAR v = SUM ( FactTraffic[Value] )
    RETURN
    IF ( v = 0, BLANK(), v )

     

    Option 2: Turn OFF “Show items with no data” (if enabled)

    Check this carefully:

    1. In the Fields pane

    2. On the Legend field dropdown

    3. Make sure “Show items with no data” is OFF

    If it’s on, Power BI will force all legend items to appear.

  • Hi MateuszW

    Because the legends are measures, applying an “is not blank” visual filter (if one is used) can produce misleading results. For example, if the first measure evaluates to blank for a given data point, the remaining measures for that same point will also return blank, even if they should logically have values.

     

    The practical workaround is to disable the built-in legend and instead use a visual that mimics the legend. Two common approaches:

    • DAX-generated SVG legend. Create an SVG image in DAX that displays the legend color and label. This works visually, but since it is a single image, the legend items are not clickable.
    • Circle SVG + button/tile slicer. Use a small DAX-generated circle SVG as the icon in a button or tile slicer and format it to look like a legend.

    Note:

    For both approaches, a disconnected table is required that lists the measure or metric names along with their corresponding colors. A measure should be created to return the appropriate value based on the metric name column.

    In the second approach, the button slicer remains clickable, but it will not filter the line chart unless the measure described above is used within the visual.

     

    Please see the attached sample pbix.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi MateuszW,

    I would also take a moment to thank danextian  , cengizhanarslan  for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.
     

    I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.

    Regards,
    Community Support Team.

  • MateuszW Hey,

    Yes—hide unused legend items by ensuring the series evaluate to BLANK and by disabling “show items with no data”.

    Do these checks/fixes:
    1) Turn off “Show items with no data”

    • In the Build/Fields pane, click the ellipsis (…) on:


    - Legend field → uncheck Show items with no data
    - X-axis field (if available) → uncheck Show items with no data

     

     

    Note : If you’re using a disconnected Categories table, it will list all categories; either relate it to the fact or keep it disconnected but ensure step 1 is applied and the chart measure returns BLANK for absent categories.

     

    Thanks

    Haish K 

    If I resolve your issue. Kindly give kudos to this post and accept it as a solution so other can refer this