Forum Discussion

Cookie_Lover's avatar
Cookie_Lover
Icon for Helper I rankHelper I
7 months ago

Filter bar chart depending on field parameters and hide bars when there are no comparison values

Hello,

 

I have the following problem:

 

I have created index values based on the Value column. Blue is assigned an index of 100 for each product. The other colors (red, green, and yellow) are then indexed based on their values.

This works without any problems.

 

Now I want to display the whole thing in a diagram. To do this, I have inserted the measures for index calculation in field parameters.

This allows me to filter which of the three colors (red, green, and yellow) is compared with blue.

 

Now I don't want to display the products that have no comparison value for blue. This varies depending on which color was selected in the filter.

The problem is that I cannot set all index calculations filters for the three colors (red, green, and yellow) to is not 0 (or is not blank) because it works like an AND condition, i.e., nothing is displayed anymore.

So what I need is a measure that, depending on the color selection in the filter, hides the products that currently have no comparison index.


Measures:

Blue as index for comparison = DIVIDE (Table1[Blue filtered for Comparison],Table1[Blue filtered for Comparison],0)*100

Blue filtered for Comparison = CALCULATE(AVERAGE(Table1[Value]),
Table1[Color] = "blue")

 

The following code I used for all three comparison colors (green, red and yellow) and changed just the color name. Here is the code for green:

Green as index for comparison = DIVIDE (Table1[Green filtered for Comparison],Table1[Blue filtered for Comparison],0)*100

Green filtered for Comparison = CALCULATE(AVERAGE(Table1[Value]),
Table1[Color] = "green")

 

Field Parameters:

Parameter = {
    ("Green as index for comparison", NAMEOF('Table1'[Green as index for comparison]), 0),
    ("Red as index for comparison", NAMEOF('Table1'[Red as index for comparison]), 1),
    ("Yellow as index for comparison", NAMEOF('Table1'[Yellow as index for comparison]), 2)
}


Data:

ProduktYear of ProductionColorValue
Computer2025red2.908.754
Laptop2025red1.000.000
Smartphone2025red5.000.356
Tablet2025red3.427.765
Computer2025blue4.000.764
Laptop2025blue2.567.875
Smartphone2025blue3.456.876
Tablet2025blue2.345.567
Smartwatch2025blue3.657.898
TV2025blue2.345.123
Radio2025blue9.876.456
Smartwatch2025green6.543.345
TV2025green7.834.345
Radio2025green1.987.456
Computer2025yellow1.238.734
Laptop2025yellow6.732.487
Smartphone2025yellow9.173.354
Tablet2025yellow8.348.321

15 Replies

  • Change your measures so they blank themselves out when data is not present, and make DIVIDE’s alternate result BLANK() (not 0). Then the bar disappears automatically.
     

    // Reuse your existing helpers
    Blue filtered for Comparison :=
    CALCULATE( AVERAGE( Table1[Value] ), Table1[Color] = "blue" )

     

    // Return BLANK when either side is missing
    Blue as index for comparison :=
    VAR Blue = [Blue filtered for Comparison]
    RETURN IF( NOT ISBLANK(Blue), 100 )

     

    repeat for the others

     

    Now, when your field parameter switches between Green/Red/Yellow, any Product lacking that color (or lacking Blue) returns BLANK(), so the bar is hidden.

    • Cookie_Lover's avatar
      Cookie_Lover
      Icon for Helper I rankHelper I

      This does not work for me. The result is the same as before.

  • Hi,

    Share the download link of the PBI file with the measures written and visual built.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Cookie_Lover,

     

    Power BI assigns legend labels and colors at the measure level. When using a single dynamic measure, colors cannot change based on slicer selection. I feel Field Parameters are the only supported way to achieve dynamic legends with correct colors.

     

    Thanks & Regards,

    Prasanna Kumar

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Cookie_Lover,

     

    Just following up to see if the Response provided by community members were helpful in addressing the issue. if the issue still persists Feel free to reach out if you need any further clarification or assistance.

     

    Best regards,
    Prasanna Kumar

     

    • Cookie_Lover's avatar
      Cookie_Lover
      Icon for Helper I rankHelper I

      Hi,

       

      the responses were helpful, but the problem still exists. 

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Cookie_Lover,

     

    Have you considered trying Field Parameters for this scenario? They might help resolve both the dynamic legend and color behavior in a cleaner way.

     

    Thanks & Regards,

    Prasanna Kumar