Excel Chart Conditional Formatting

Craig from Lloyds Banking Group asked if Excel’s conditional formatting can be applied to charts.  I’d like to provide the answer in the form of a news sandwich (good news, bad news, good news).

It’s a nice sunny day as I’m writing this article.

No, you can’t I’m afraid, Craig.

You can create a pseudo conditionally formatted chart.

Excel Conditional Formatting – a Recap

You have a list of customer accounts and due dates in Excel.  You want to highlight customers who have due dates within the next week in orange and you want to highlight customers who have due dates within 2 days in red.  That makes your list more readable and Excel more human.  Back in the old days of Excel 2003 you’d need to do some functions to achieve this and you were limited to 3 conditions per cell.  Conditional Formatting was introduced in Excel 2007 and has improved ever since.  It allows the user to create some nifty formatting based on cell values with just a few clicks.

Excel Conditional Formatting Date Example

 

You can also choose conditions based on averages, top %, text occurring, duplicate values and many more.  You can also use icons such as red, amber and green or perhaps smiley faces.  And also you can choose data bars which allow you to visualise the value according to magnitude.

Excel 2013 Data Bars screenshot

 

So Craig’s question asked if one can apply this Conditional Formatting feature to bars or segments within Excel charts?

And if you recall, the answer is no but you can create a similar experience by categorising the data into distinct, banded columns and charting those.  Let’s take a table (below) with data series and values which we want to chart.

Excel table ready for conditional formatting

 

A default chart will represent each column in the same colour (below).

Excel chart without conditional formatting

We want each bar coloured according to the band of values it falls into.  To do this we can create the bands we want to chart as additional columns in the table (below).  In rows 1 and 2 we list the boundaries of each band (e.g. 0 and 500).   Each value cell (G4-M16) is then calculated using a formula =IF(AND(G$1<$F4,$F4<=G$2),$F4,””).  For each cell, the Amount (F4-F16) is compared to the boundaries.  If the value falls within a boundary then value is written into that cell, otherwise it’s left blank.  The result is our mapped table below.

Chart with additional columns for conditional formatting

 

Now if we click on the default chart we created earlier, Excel highlights the table data used for the chart (below).

Excel data used for the default chart

 

Drag the red and blue boxes to select our new data (below).

New data selection for chart

 

And voila, we have our chart with conditionally coloured bands and a key to those bands (below).  Note, in true Blue Peter fashion I’ve adjusted the colours for each band and also adjusted the gap and spacing of the bars (simply double-click on any of the bars and you’ll have access to those settings).  This is a rough and ready but effective solution.  It won’t be the most efficient for large volumes of data because we are running the calculations for every cell repeatedly.  We could use VBA for a more efficient method but that’s another blog entry for the future…

Excel chart with conditional formatting