Hourly Goals Chart with Conditional Formatting

Share

Facebook
Twitter
LinkedIn

A while back I developed a solution to a Chandoo.org Forum question, where the user wanted a 4 level doughnut chart where each doughnut was made up of 12 segments and each segment was to be colored based on a value within a range.

HGC01

You can read the original post here: http://forum.chandoo.org/threads/hourly-goals-chart.30621/

This post will examine the techniques I used for the solution.

Data

Download the sample file: Download Hourly Goals Chart File

HGC02

The first thing to note is that there are 4 column of data, one for each measure of Safety, Quality, Delivery and Cost.

Secondly is that each measurement has 12 values representing the times from 4:30 am to 3:30 pm.

We need to setup a Doughnut Chart with 4 layers of 12 segments each

The easiest way to do this is to replicate the data area, but fill it with the same value in all cells,

I choose 1, but as long as all values are the same value, it can be any value

HGC03

Add a Doughnut Chart

Select the Range A16:E28

Goto the Insert, Chart and select the Pie/Doughnut menu

HGC04

HGC05

We have a bit of work to do yet to get the charts format correct

First select the chart then select the Chart’s Legend and press Delete

HGC06

Next with the chart still selected, Right Click on any Doughnut and select Format Data Series

Set the Doughnut Hole Size to 25%

Do not change the angle of the first slice

HGC07

Right  click on the Outer Doughnut and select Add Data Labels, Data Labels

HGC08

Right Click on any Data Label and Select Format Data Labels

Tick Value From Cells, Select a range A17:A28

Untick Value

Untick Leader Lines

HGC09b

Now manually click and drag each data label outwards to its final location

HGC10

 

Finally set the Border Color for the doughnuts

Right Click on each Doughnut in turn

Set the Doughnut’s Border Line to a Grey Color and a 2 Pt line size

HGC11

We can now add a text box for the Doughnut Labels

With the chart selected, goto the Insert, Text Box menu

Drag a Text Box inside the chart

Right click on the Text Box and edit Text and type in the value Cost

Now repeat this for the other 3 Doughnuts

HGC31

 

Connect the Doughnut Segments to the Data Area

We now have a basic Doughnut chart with all the facilities we require.

Unfortunately, Excel doesn’t have a built-in Conditional Formatting option for charts.

So we will need to develop a system using some simple VBA.

Understand the Doughnut Chart

To write a piece of code we will need to loop through each segment of each doughnut and reference it back to the source data area

Then use some code to set the fill color

then repeat for each segment

 

To do this we need to understand which doughnut is which column of data and which segment in the doughnut is which time period

First select the inner Doughnut, Note that when you select it, Excel highlights the Safety Series as well as showing the Series Number in the Formula Bar

HGC12a

Repeat with the outer Series and you will see that Doughnut 4 is connected to the Cost Data and is series 4.

HGC12b

To determine which segment is which goto cell E17 and change the value from 1 to 2

HGC13b

So we understand that the series go from Value 1 to 4, Inner to Outer Doughnuts and that the segments go from value 1 to 12 clockwise, starting to the right of 12 O’Clock.

Finally select the Chart and make note of it’s name.

The Charts Name is shown in the Name Dialog above cell A1

HGC16a

Now for some VBA

Lets start by first manually recording a macro in VBA and we will then edit and add to the macro to get our final result

Start the macro Recorder by Pressing the Macro Button in the lower left corner of the Excel Window

HGC14a

Note the Macro Name, which is most likely Macro1 and press Ok

Now everything that you do is being recorded by the Visual Basic Editor (VBE)

Select the Outer Doughnut, then select Segment one, then Right Click on Segment one, Format Data Point

Select the Fill & Line menu

Set the Fill to a Solid Fill and Select a Color Red

You can now stop macro recording by pressing the Macro button again

HGC15a

 

Lets look at our code

To change to VBA press the Alt+F11 button

You should have a screen similar to this:

HGC17

Take note of the above.

We can see that we have a Macro1 subroutine, located in Module 1 of our Excel file.

If you can’t see a Properties or Immediate window, don’t worry.

Looking at the VBA Code we can see

HGC18

  1. That the chart is called Chart 1
  2. We selected Doughnut 4, the outer doughnut
  3. We selected the first segment in Doughnut 4
  4. We set the Fill Color of Segment 1 to Red  = RGB(255, 0, 0)

So this little bit of code will form the basis of our macro

What we need to do next is to place that within 2 loops, one loop for the Doughnut and one loop for the Segment

So lets do that:

HGC19

You can see above that we have initialised two variables Doughnut and Segment as Integers

We have setup two loops, one for the Doughnut which will loop from 1 to 4 and a second loop for the Segment, which will loop from 1 to 12.

We can now use these variables within the code to reference each Doughnut / Segment as relevent

HGC20

The next thing is to add lines to lookup the value of the measure in the original data table.

We can use our variables to assist us with this:

I have added a new variable declaration myVal and declared it an Integer as it is only storing the values from, 0 to 3.

Then we retrieve the value from the data area by using a Range(“”).Offset(Row,Column) combination.

We know that the segment loops from 1 to 12 and this is the Row Offset in each Doughnut.

The Doughnut loops from 1 to 4 and this is the Column Offset from the cell A1

 

 

HGC21

Next we need to allow for each fill color remembering that the data area has a legend

HGC22

We could loop from a value of 0 to 3 and check the new variable myVal against each value and set the color.

But VBA has a Select Case function which is ideally suited to this task

HGC23

A also took the opportunity to streamline the Chart selection process in the previous step

That allowed the use of the With Object construct, allowing the Select case to use the myVal to apply different colors to the fill property of each segment

 

At this stage we can run the code, by simply pressing F5 in VBA

HGC24

 

We can change the code to allow it to update automatically when Data range changes

To do this we need to shift the code to a Sheet1 Code Module associated with Worksheet Sheet 1

HGC26

Note above that the code is now located in a Private Sub Worksheet_Change event. This means that the code runs whenever worksheet1 chnages.

The next line If Intersect(ActiveCell, Range(“B2:E13”)) Is Nothing Or Target.Count > 1 Then Exit Sub

Checks whether the cell that changed was not part of our Data Area or that multiple cells were selected.

If either are are true the macro ends

Then finally I removed the MyVal calculation and made it part of the Select Case function.

because we aren’t using myVal I removed the Dim myVal statement

We can now also remove Module 1, right click on it and Remove Module.

Save the file and return to Excel with Alt+F11

You can now change any cells in the data area and the macro updates the chart accordingly

Can we tidy up the layout of the worksheet?

Although we now have a fully functional model, we are stuck with an ugly worksheet layout because our template of 1’s is being used to support the framework of the 4 Doughnuts in the chart.

What if there was another way to achieve that?

Well there is.

Firstly, we could simply shift the range A18:ER30 well away from the Chart and data area or even move it to another worksheet.

HGC27

This will work, but risks a person adding data, rows or columns and messing up the layout

But there is a better way

I am going to add 4 Named Formula to the worksheet, one for each Doughnut

Goto the Formula, Name Manager Tab and add 4 Names as listed below:

_Safety      =1+(ROW(OFFSET(Sheet1!$A$1,,,12,1))-1)*0

_Cost        =_Safety

_Delivery  =_Safety

_Quality  =_Safety

HGC28

The 4 Names now contain an array of 12 x 1 each with a value 1.

We can use that to link the Doughnuts to instead of the Physical Range

Right click on the chart and Select Data

HGC30

Select each Doughnut in term and Edit

Change the Series Name to Row 1 and insert the Names into the Series values dialog.

Note that the formula must include the Worksheet name =Sheet1!_Safety etc

HGC29

Repeat this for the 4 Series

You can now select the framework range: A18:E30 and press Delete

HGC32

The chart remains intact and is now supported by the Named Formula

Change some values in the Data range at the top and the Chart updates as it should.

You can download the final version of the file here: Download Completed File

Final Thoughts

The technique applied to the doughnut chart above can fairly easily be modified to any chart type or in fact any other shapes.

Let me know what you think in the comments below:

ps: This has been one of my hardest posts to write, simply because Microsoft has misspelt Doughnut. In my native Australian English it is Donut.

 

 

 

 

 

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

31 Responses to “Beautiful Budget vs. Actual chart to make your boss love you”

  1. Harry says:

    Would be considerably easier just to have a table with the variance shown.

  2. Jomili says:

    On Step 3, how do you "Add budget and actual values to the chart again"?

    • Chandoo says:

      There are a few ways to do it.

      Easy:
      1) Copy just the numbers from both columns (Select, CTRL+C)
      2) Select the chart and hit CTRL+V to paste. This adds them to chart.

      Traditional:
      1) Right click on chart and go to "select data..."
      2) From the dialog, click on "Add" button and add one series at a time.

      • Neeraj Agarwal says:

        One more way to accomplish it is just select the columns into chart. Press Ctrl+C and then press Ctrl+V

        Regards
        Neeraj Kumar Agarwal

  3. TheQ47 says:

    Unfortunately, this doesn't seem to work for me in Excel 2010. The "Var 1" and "Var 2" columns cannot combine two fonts to display the symbol and the figure side-by-side.
    Secondly, there is no option to Click on “Value from cells” option when formatting the label options. The only options provided are Series Name, Category Name or Value.

    • Chandoo says:

      @TheQ47... the emoji font also has normal English letters, so if you use that font, then you should be ok. I am assuming your computer doesn't have that font or hasn't been upgraded for emoji support.
      Reg. Excel 2010, you can manually link each label to a cell value. Just select one label at a time (click on labels, wait a second, click on an individual label) and press = and link it to the label var 1 or var 2.

  4. Neeraj Agarwal says:

    I am using excel 2010, please explain how to apply Step 12

    Regards
    Neeraj Kumar Agarwal

  5. mariann says:

    Hi Chandoo,

    I just found your website, and really love it. It helps me a lot to be an Excel expert 😉

    Currently I am facing with a problem at step 11:
    Var1 Var2
    D30%
    A5%
    B0%
    B4%
    B7%
    C10%
    C13%
    D27%
    I42%

    Though at mapping table, I used windings, here formula uses calibra. How I can change it? I am able to change only the whole cell. In this case numbers will be Windings too.

    Thanks for your help!

    • Chandoo says:

      Hi Mariann... Welcome to Chandoo.org and thanks for your comment.

      If you wanted to use symbols from wingdings and combine them with % numbers, then you need to setup two labels. One with symbol, in wingdings font and another with value in normal font. Just add the same series again to the chart, make it invisible, add labels. You may need to adjust the alignment / position of label so everything is visible.

  6. […] firs article explains how you can enhance your charts with symbols. You can simply insert any supported symbol into your data and charts. To some extend you can […]

  7. Franciele says:

    You're a good person, thank you to share your knowledge with us, I will try to do in my work

  8. Ali says:

    Great visualization of variance. My question is that is this possible in powerbi?

    How would you go about it?

  9. NARUTO says:

    HELLO, WHY CANT I FIND VALUES FOR LABELS IN EXCEL 2013

  10. Amol says:

    Dear chanddo sir,

    What to do if we have dynamic range for Chart. How this will work. can you able to make the same thing works on dynamic range.

  11. Ricardo says:

    Sir Chandoo,

    Good Day!
    First, I'd like to say that I am very grateful for your work and for sharing all these things with us.

    I tried to do this chart but it seems that the symbols don't work with text (abs(var%),"0%") unless we keep the Windings font style.
    The problem is, it converts the text into symbol as well and you wont see the 0% anymore. I'm using Windows 7.

  12. MF says:

    WOW - Segoe UI Emoji
    This is the greatest discovery for me this month 🙂 Thanks for sharing.

    Here's my two-cents:
    https://wmfexcel.com/2019/02/17/a-compelling-chart-in-three-minutes/

  13. Renuka says:

    Sir This is awesome chart, and very easy to made because of your way to explain is very simple , everyone can do. Thank you

    one problem i am facing, I hv made this chart , but when i am inserting data table to chart it is showing two times , how can i resolve this

  14. renuka says:

    in this chart when i am adding new month data for example first i made this chart jan to mar but when i add data for the apr month graphs updated automatically but labels are missing for that new month

    • Chandoo says:

      Hi Renuka,

      Please make sure the formulas for labels are also calculated for extra months. Just drag down the series and set label range to appropriate address.

  15. Justine says:

    So I am playing with the Actual chart here - but amounts are bigger than your - you have 600 as Budget - my budget is 104,000 - is there a way to shorten that I am unaware of

    thank you - I LOVE YOUR SITE

  16. Arvind says:

    Thanks for the tips and tricks on Excel. In the Planned versus Actual chart examples, you use multiple values (ex. multiple Categories in above). How can this be done when we have only 1 set of values? For example if I have only this:
    Planned Actual
    SOW Budget 417480 367551

    How can I create a single bar chart like the one above?

  17. JEREMIAH KOOL says:

    Thank you Chandoo.
    This one is just perfect for my Quarterly Review presentation on Operational Budget against Actual Performance for the Hospital I'm currently working with.

    Just Subscribed today (10 minutes ago)

  18. Shawn says:

    Is there a way to make the table of data into a pivot table to be able to add a slicer for the graph due to many different categories and months?

  19. Mihail says:

    Hi, I tried to modify you template with something appropriate for me, and I found a problem. this template was modified by me started with excel 2010, then 2016 and finally 2019. Same thing - somehow appear an error - or didn't show the emoticons for positive percentage or doubled the emoticons for some rows. I suspect to be from excel. if is need it I can sand you my xlsx for study. Please help if you can.

  20. Saidatta Pati says:

    Hi Chandoo,
    Could you please check the Var Formula in Step1. You have mentioned budget-actual and when i did this i got different values but when reversed like actual-budget i got the actual value what you have demonstrated in step1.
    Please share your view.

  21. Dan says:

    This is a great chart (budget vs. actual). However, in trying recreate it, I cannot color in the UP Down bars individually, and they all become formatted with the same color. I'm using Office 365. Look forward to the feedback.

    Thanks.
    Dan

  22. sathik says:

    pls explain in detail step 7

  23. Arun says:

    While in the Excel sheet you have used following formula for Var
    Var = Actual - Budget
    But
    in the note, you have written
    Var = Budget - Actual

  24. aye myat maw says:

    Good Presentation and Data information.thank you so much chandoo.

Leave a Reply