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
bezawak
Frequent Visitor

Don't want to change the legend color in date category in bar chart of tree chart in Power BI

When there is change in the data the colors of the legend in the date category changes automatically for bar chart or tree chart 

is there a way to over ride data category color and keep it same as even the back end data changes :

 

Examaple : Bar Chart --We have bins like bin1 0 -5 days ,bin2 5 -10 ( We have one color for each bin )

Now when we change the bin to bin1 :0-10 bin 2 :10-15 the color of the previuous bins defined will go away is there a way to keep the color same even thought when we change the bins ...this is typical bussiness requirmet help is much appreciated 

 

Thanks

Kalyana

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @bezawak ,

 

Please check if this could meet your requirements:

 

1. Create columns like so:

bin = 
SWITCH (
    TRUE (),
    [days] >= 0
        && [days] <= 5, "0-5 days",
    [days] > 5
        && [days] <= 10, "5-10 days",
    [days] > 10
        && [days] <= 15, "10-15 days"
)
bin sort = 
RANKX (
    'Table',
    CONVERT (
        LEFT (
            SUBSTITUTE ( [bin], " ", "-" ),
            SEARCH ( "-", SUBSTITUTE ( [bin], " ", "-" ) ) - 1
        ),
        INTEGER
    ),
    ,
    ASC,
    DENSE
)

 

2. Create a bin color measure.

bin color = SWITCH ( MAX ( 'Table'[bin sort] ), 1, "Red", 2, "Blue", 3, "Yellow" )

 

3. Set data colors.

data.PNG

 

4. Then you will get this:

color.gif

 

BTW, .pbix file attached.

 

 

 


Best Regards,
Icey

View solution in original post

5 REPLIES 5
Icey
Community Support
Community Support

Hi @bezawak ,

 

I have posted one workaround. Please check.

 

 

Best Regards,

Icey

Icey
Community Support
Community Support

Hi @bezawak ,

 

Please check if this could meet your requirements:

 

1. Create columns like so:

bin = 
SWITCH (
    TRUE (),
    [days] >= 0
        && [days] <= 5, "0-5 days",
    [days] > 5
        && [days] <= 10, "5-10 days",
    [days] > 10
        && [days] <= 15, "10-15 days"
)
bin sort = 
RANKX (
    'Table',
    CONVERT (
        LEFT (
            SUBSTITUTE ( [bin], " ", "-" ),
            SEARCH ( "-", SUBSTITUTE ( [bin], " ", "-" ) ) - 1
        ),
        INTEGER
    ),
    ,
    ASC,
    DENSE
)

 

2. Create a bin color measure.

bin color = SWITCH ( MAX ( 'Table'[bin sort] ), 1, "Red", 2, "Blue", 3, "Yellow" )

 

3. Set data colors.

data.PNG

 

4. Then you will get this:

color.gif

 

BTW, .pbix file attached.

 

 

 


Best Regards,
Icey

amitchandak
Super User
Super User

@bezawak , Any visual using legend or details can not have conditional formatting and we can not control sequence of color. Please see there might be an idea on that. Vote for that or log a new one.

 

https://ideas.powerbi.com/forums/265200-power-bi-ideas

AllisonKennedy
Super User
Super User

You could use the Theme and Sort Order for the bins, so that the default colours match the colours you want the bins to adopt. So basically, updating the theme in json to have the first few colours equal to the selected bin colours, then add a sort order on the Bin column to always sort in the same order, even when the bins change in the back end. Does that make any sense?

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

jdbuchanan71
Super User
Super User

@bezawak 

Try re-applying your theme to the .pbix file after categories have changed.  What I have seen is colors 1, 2 and 3 will be applied to categories 1, 2, and 3 (0-10, 11-20, 21-30) and when the categories change it applies the next colors to the new categories.  Re-applying the them applies colors starting at 1 to the new categories.

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.