Forum Discussion
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:
| Produkt | Year of Production | Color | Value |
| Computer | 2025 | red | 2.908.754 |
| Laptop | 2025 | red | 1.000.000 |
| Smartphone | 2025 | red | 5.000.356 |
| Tablet | 2025 | red | 3.427.765 |
| Computer | 2025 | blue | 4.000.764 |
| Laptop | 2025 | blue | 2.567.875 |
| Smartphone | 2025 | blue | 3.456.876 |
| Tablet | 2025 | blue | 2.345.567 |
| Smartwatch | 2025 | blue | 3.657.898 |
| TV | 2025 | blue | 2.345.123 |
| Radio | 2025 | blue | 9.876.456 |
| Smartwatch | 2025 | green | 6.543.345 |
| TV | 2025 | green | 7.834.345 |
| Radio | 2025 | green | 1.987.456 |
| Computer | 2025 | yellow | 1.238.734 |
| Laptop | 2025 | yellow | 6.732.487 |
| Smartphone | 2025 | yellow | 9.173.354 |
| Tablet | 2025 | yellow | 8.348.321 |
15 Replies
- Thomaslleblanc
Super User
Change your measures so they blank themselves out when data is not present, and makeDIVIDE’s alternate resultBLANK() (not0). Then the bar disappears automatically.// Reuse your existing helpersBlue filtered for Comparison :=CALCULATE( AVERAGE( Table1[Value] ), Table1[Color] = "blue" )// Return BLANK when either side is missingBlue 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
Helper I
This does not work for me. The result is the same as before.
- Ashish_Mathur
Super User
Hi,
Share the download link of the PBI file with the measures written and visual built.
- Cookie_Lover
Helper I
Here is the PBI file:
Index_Comparison.pbix- Ashish_Mathur
Super User
Hi,
You do not need field parameters here. See the second page of the file.
- AnonymousNot 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
- AnonymousNot 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
Helper I
Hi,
the responses were helpful, but the problem still exists.
- AnonymousNot 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