Forum Discussion
Stacked bar chart doesnt's show values based on filter.
Hi,
I try to create stacked bar chart with a legend with two different values - one of them is green, second - red. I want to keep sum of those two at the chart. I don't want to see red and green values separately on chart - always a total.
Problem I stumbled is if I filter the data to show only red values my label doesn't show up. In case of filtering the data I want to display label of only selected filter.
I created three measures: CALCULATE sum of reds, CALCULATE sum of greens and then SUM of both of them. I thought that might be the answer but it isn't.
What should I do to achieve desired chart?
7 Replies
- AnonymousNot applicable
Hi, MFelix. I think I might be trying to do the same thing as piotr_gor.
I have a stacked bar chart where the Product is on the Y-axis and the Color is the Legend. I also have a slicer to choose either Green, Red, or both. If I select Green, I want the data label to reflect the value for Green. If I select Red, I want the data label to reflect the value for Red. If I select both, I want the data label to reflect the total for both Red and Green without showing the individual data label for both. I just want the total. Currently, having the Total labels switched on gives the desired result only if I've selected both Red and Green. If I only select one color, no data label is displayed.
The image above is my desired outcome.
Thankful for any help you're able to provide.- MFelix
Super User
Hi Anonymous ,
What happens is that when you have a single value there is no total lables because it's a single value.
In this case you need to create the following measures:
Total Quantity = SUM('Table'[Quantity]) Color Coding = var ColorQuantity = CALCULATE([Total Quantity], ALLSELECTED('Table'[Color])) var TotalQuantity = CALCULATE([Total Quantity], ALL('Table'[Color])) Return IF(ColorQuantity = TotalQuantity,SELECTEDVALUE('Table'[Color]) ,"Black")Now use your color coding as a conditional formatting on the data labels:
- AnonymousNot applicable
Hi piotr_gor ,
You could create a measure like below:
Measure = CALCULATE ( SUM ( 'table'[value] ), ALLEXCEPT ( 'table', 'table'[Product] ) )Best Regards,
Jay