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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
MWC914
Frequent Visitor

Conditional Format Bars and Line in a combo chart by year

Is there a way to format a combo chart to differentiate the bars and line conditionally based on the year?

As you can see in the first screenshot, each year is a different color, and the average line matches the color of the bar. 

 

While I see the option to format the column in power bi based on a function, I do not see anything for the line. 

 

Desired Outcome FormatDesired Outcome FormatPower BIPower BI

5 REPLIES 5
Anonymous
Not applicable

Hi  @MWC914 ,

 

It's not clear what you mean, if you want to highlight the specified data of the legend, you can click on it with the left mouse button. If the above results do not meet your expectations, you can express your expectations in the form of a picture, we can help you better!

vyangliumsft_0-1728979880132.png

 

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I meant if you could make the legend only display the value for the column, in this case Value1, and subsquently remove the individual line segments (2023year, 2024year, etc.). My data would be going back as far as 2015 and I would not want all 10 years showing up in the legend, just the column. 

Anonymous
Not applicable

Thanks for the reply from PhilipTreacy , please allow me to provide another insight: 
Hi  @MWC914 ,

I created some data:

As far as I know, Line Chart and Clustered Column Chart doesn't support customizing the color of Line y-axis, this is due to the design of Power BI, you can use the following method instead: multiple measures are created, and each measure only displays the data corresponding to the year, otherwise it is empty.

vyangliumsft_0-1728541111129.png

Here are the steps you can follow:

1. Create measure.

2023year =
var _mindate=MINX(FILTER(ALL('Table'),YEAR('Table'[Date])=2023),[Date])-1
var _maxdate=MAXX(FILTER(ALL('Table'),YEAR('Table'[Date])=2023),[Date])
return
IF(
    MAX('Table'[Date])>=_mindate&&MAX('Table'[Date])<=_maxdate,SUM('Table'[VALUE2]),BLANK())
2024year =
var _mindate=MINX(FILTER(ALL('Table'),YEAR('Table'[Date])=2024),[Date])-1
var _maxdate=MAXX(FILTER(ALL('Table'),YEAR('Table'[Date])=2024),[Date])
return
IF(
    MAX('Table'[Date])>=_mindate&&MAX('Table'[Date])<=_maxdate,SUM('Table'[VALUE2]),BLANK())

2. Lines - Apply settings to (select specified measure name) - Color (set different color).

vyangliumsft_1-1728541111130.png

3. Result:

vyangliumsft_2-1728541165340.png

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Thank you very much, that's a very clever workaround!

 

Do you know if there is a way to certain items from the legend? I just looked and did not see that as an option. I could always insert a text box but would prefer to have a more automated solution. 

PhilipTreacy
Super User
Super User

@MWC914 

 

Download PBIX file with the example below

 

Currently it's not possible to apply a CF function to the line.  It's all one colour you manually choose.

 

You can create a rule for the columns though.

 

Create this measure

 

CF Year = 

VAR _year = YEAR(MAX('DataTable'[Date]))

RETURN

SWITCH(

    TRUE(),

    _year = 2011, "magenta",

    _year = 2012, "green",

    _year = 2013, "blue",

    _year = 2014, "black"

)

 

then create a CF rule like this

 

PhilipTreacy_0-1728516615262.png

 

Giving this

 

PhilipTreacy_1-1728516645547.png

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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