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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Agent47
Helper I
Helper I

Data Bar conditional formatting

Agent47_0-1731476080619.png

In tableau , this visual uses a legend for colouring.

Agent47_1-1731476122669.png

In power BI , the closest I could get to is this. 
Can I somehow recreate colours in Data Bar conditional formatting so that it matches the tableau visual.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Agent47 ,

 

As danextian said, you need to check a measure first:

2024-11-15_14-38-45.gif

Again, you can continue to define the conditional format under each country, and here I've assigned three colors to [Total Profit] equals Maximum Minimum as well as Middle under Canada.

VAR RectColor =
    SWITCH (
        SELECTEDVALUE ( 'financials'[Country] ),
        "Canada",
            VAR __vals =
                CALCULATETABLE (
                    ADDCOLUMNS (
                        SUMMARIZE ( 'financials', 'financials'[Country], 'financials'[Product] ),
                        "@TotalProfit", [Total Profit]
                    ),
                    ALLSELECTED ( 'financials'[Product] )
                )
            VAR __minvalue =
                MINX ( __vals, [@TotalProfit] )
            VAR __maxvalue =
                MAXX ( __vals, [@TotalProfit] )
            VAR __color =
                SWITCH (
                    TRUE (),
                    [Total Profit] = __maxvalue, "#06B050",
                    [Total Profit] = __minvalue, "#D41F26",
                    "#3b3a39"
                )
            RETURN
                __color,
        "France", "Red",
        "Germany", "Yellow"
    )

vcgaomsft_0-1731654393375.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @Agent47 ,

 

Try using SVG + DAX:

SVG_Total_Profit = 
VAR MinValue = 
    MIN ( MINX ( ALLSELECTED ( 'financials'[Country],'financials'[Product] ), [Total Profit] ), 0 )
VAR MaxValue = 
    MAX ( MAXX ( ALLSELECTED ( 'financials'[Country], 'financials'[Product] ), [Total Profit] ), 0 )
VAR Gap_Value = MaxValue - MinValue
VAR X = 720 * [Total Profit] / Gap_Value
VAR TextValue = FORMAT([Total Profit], "#,##0.00")
VAR RectColor = SWITCH(SELECTEDVALUE('financials'[Country]), "Canada", "Green", "France", "Red", "Germany", "Yellow")
VAR StartX = 
    IF([Total Profit] >= 0, 0, 720 + X)
VAR Height = 150
VAR FontSize = 100 
VAR TextXOffset = 10 
VAR FontFamily = "Arial" 
RETURN 
"data&colon;image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='720' height='" & Height & "'>
<rect x='" & StartX & "' y='0' width='" & ABS(X) & "' height='" & Height & "' fill='" & RectColor & "'/>
<text x='" & StartX + TextXOffset & "' y='50%' font-size='" & FontSize & "' text-anchor='start' dominant-baseline='central' fill='black' font-family='" & FontFamily & "'>" & TextValue & "</text>
</svg>"

vcgaomsft_0-1731574960725.png

vcgaomsft_1-1731575074799.png

Remember to categorize it as an image URL.

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Hi @Anonymous  , what if I need just like 3 different colours for Canada , France , Germany ? No min , max , nothing . Also will I write it as a measure ? And I could not find the measure tools option in my power bi Version: 2.137.751.0 64-bit (October, 2024)

Anonymous
Not applicable

Hi @Agent47 ,

 

As danextian said, you need to check a measure first:

2024-11-15_14-38-45.gif

Again, you can continue to define the conditional format under each country, and here I've assigned three colors to [Total Profit] equals Maximum Minimum as well as Middle under Canada.

VAR RectColor =
    SWITCH (
        SELECTEDVALUE ( 'financials'[Country] ),
        "Canada",
            VAR __vals =
                CALCULATETABLE (
                    ADDCOLUMNS (
                        SUMMARIZE ( 'financials', 'financials'[Country], 'financials'[Product] ),
                        "@TotalProfit", [Total Profit]
                    ),
                    ALLSELECTED ( 'financials'[Product] )
                )
            VAR __minvalue =
                MINX ( __vals, [@TotalProfit] )
            VAR __maxvalue =
                MAXX ( __vals, [@TotalProfit] )
            VAR __color =
                SWITCH (
                    TRUE (),
                    [Total Profit] = __maxvalue, "#06B050",
                    [Total Profit] = __minvalue, "#D41F26",
                    "#3b3a39"
                )
            RETURN
                __color,
        "France", "Red",
        "Germany", "Yellow"
    )

vcgaomsft_0-1731654393375.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Measure tools is a contextual tab which appears when a measure is selected from the field pane. You will need to specify the min max/values to calculate the length of the bar. Unlike with the native databar option, this needs to be calculated when using SVG images. Also take note that exporting the data from the matrix will export the SVG markups and not the actual values.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
danextian
Super User
Super User

Hi @Agent47 

For databars, we are stuck at selecting one color for negative and another one for positive values. There is also no option to select another measure.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Uzi2019
Super User
Super User

Hi @Agent47 

 

Unfortunetly No. There is very limited option available under fx of bar conditional formatting.

Uzi2019_0-1731478763790.png

 

 

As you can see you can just set to min to max color for gradient effect.  not based on row header values.

 

But you can try below videos

https://www.youtube.com/watch?v=DmLozWHekMA

 

I hope I answered your question!

 

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.