Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
piotr_gor
Helper II
Helper II

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.  

piotr_gor_1-1656655183130.png

 

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. 

piotr_gor_2-1656655444957.png

 

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 7
v-jayw-msft
Community Support
Community Support

Hi @piotr_gor ,

 

You could create a measure like below:

Measure =
CALCULATE ( SUM ( 'table'[value] ), ALLEXCEPT ( 'table', 'table'[Product] ) )

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
MFelix
Super User
Super User

Hi @piotr_gor 

 

If you want to always get the values of the red and green your metric need to use a ALL statment to pass over the filter of the red / green.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi, @MFelix. I think I might be trying to do the same thing as @piotr_gor.

DataOnIce_2-1697707037429.png

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.

Hi @DataOnIce ,

 

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:

MFelix_0-1697790008478.png

 

MFelix_1-1697790019798.png

 

MFelix_2-1697790117150.png

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thank you @MFelix 

Ended up using the code below:

Color Coding =
VAR RightsSelection =
SELECTEDVALUE ( SlicerRights[Rights] )
RETURN
SWITCH (
TRUE (),
AND ( [GBO] = [GBO_RightsNo], ISBLANK ( RightsSelection ) ), "#118DFF",
AND ( [GBO] = [GBO_RightsYes], ISBLANK ( RightsSelection ) ), "#12239E"
)

Please let me know if you think it can be made more efficient.

Hi @DataOnIce ,

 

Look good.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thank you @MFelix 

I think I kind of understand. Are you able to help modify the measure so that the legend is actually between Yes and No instead of Red and Green where the color code for Yes is #12239E and the color code for No is #118DFF?

Will the one below work or is there a more efficient approach?

Color Coding =
VAR SelectedRights = SELECTEDVALUE(ReleasesDetails[Rights])
RETURN
IF (
SelectedRights = "No",
"#118DFF",
IF (
SelectedRights = "Yes",
"#12239E",))

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.