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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Saud19999
Frequent Visitor

Stacked bar chart with percentage conditional formatting

hey there,,

as shown below I want to format my stacked bar with the percentage conditional formatting, the issue happened by adding two X-axis measures in the visual..

is there a way to add conditional formatting while having two X-axis?

here is the BI file sample.pbix

thanks.Slide1.PNGSlide2.PNG

11 REPLIES 11
MFelix
Super User
Super User

Hi @Saud19999 ,

 

Do you need to have the white bar until the 100%? 


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 @Saud19999 ,

 

Do the following:

  • Create a table with your categories of colours this needs to have two values one for the bar and another with the difference to 100%

MFelix_0-1689152016946.png

  • Add the following measure:
ClusterCalculation =
VAR _Valueto100 =
    1 - DIVIDE ( [Last day all clusters - tank], SUM ( Capacity[Capacity] ) )
RETURN
    IF (
        SELECTEDVALUE ( Capacity[Cluster] ) <> BLANK (),
        SWITCH (
            TRUE (),
            SELECTEDVALUE ( Categories[Subcat] ) = "Diff"
                && DIVIDE ( [Last day all clusters - tank], SUM ( Capacity[Capacity] ) )
                    - MIN ( Categories[Minimum] ) >= 0
                && DIVIDE ( [Last day all clusters - tank], SUM ( Capacity[Capacity] ) )
                    - MAX ( Categories[Maximum] ) <= 0, _Valueto100,
            IF (
                DIVIDE ( [Last day all clusters - tank], SUM ( Capacity[Capacity] ) )
                    - MIN ( Categories[Minimum] ) >= 0
                    && DIVIDE ( [Last day all clusters - tank], SUM ( Capacity[Capacity] ) )
                        - MAX ( Categories[Maximum] ) <= 0,
                DIVIDE ( [Last day all clusters - tank], SUM ( Capacity[Capacity] ) )
            )
        )
    )

 

  • Make you chart with the follwing setup
    • Y-Axis: Cluster
    • X-Axis: ClusterCalculation
    • Legend: Category (from the new table)
    • Format the color for each of the group accordingly to your needs:

MFelix_1-1689152187378.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  for you time and help.

It's working for only3 colors , whan there is a green or yelow case it does not show it.

is there anyway solution around it?

In the example I created there was only 3 groups with data because when there a no values it returns blank, when you have more groups go to the colours and select the correct colour for the specific value.

 

If that does not work can you tell me the filters you are applying so I can get more than. 2 colors. 


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 again for your fast answer,

your example is splendid, however, it has some blank values even though there are data (shown below).

and if you could please add the 2 colours your solution would be perfect 

also is there a way to sort the values based on their value? from highest to lowest.

 

thank you again 

Saud19999_0-1689228933639.png

 

Hi @Saud19999 ,

 

Check the file updated attach.


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



great, now all colors are visible, but I still have an issue with blank values even though it's not empty..

also, the visual works excellent when there is a month selected but in my case, it's a trend for the whole year so I cant use filters

 

as you can see here a comparison with filter and without.

Saud19999_0-1689246940544.png

 

Saud19999_1-1689246957556.png

 

Can you tell me wich one is correct? So I can check the calculations


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



any help ? @MFelix 

MFelix
Super User
Super User

Hi @Saud19999 ,

 

When you refer that you are adding two axis you mean you are using the legend to make the colours correct?

 

Power BI does not allow to have condittional formatting while using the legend or more than one measure on the values.

 

The file is asking for login can you share it again please.


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



yes, that's correct..

I tried opening the file and it opens without any problem, you can download it directly 

Saud19999_0-1689065050707.png

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors