cellMatrix.net

Spreadsheet Modeling and Related Topics

Bar Chart - Exclude Zero Values

In a previous post titled Pie Chart - Exclude Zero Values, formulas were provided that sort data while excluding zero values. This post explains how to achieve the same functionality without sorting the data.

Begin with the simple two-column data set below.

image

Add a set of helper columns similar to what is shown below. These helper columns will serve as the chart source.

image

Next, create two named ranges. The first named range covers the range C4:C12. In this example I've named that range "Data".

image

The second named range covers the range B4:B12. I've named that range "DataX".

image

At this point it's time to add two array formulas to the helper columns to extract the data for the chart. Array formula are entered into a range using the Contol - Alt - Enter keystokes.

The first formula is a multi-cell array and covers the range G4:G12. The formula is:

{=INDEX(Data,SMALL(IF(Data<>0,ROW(INDIRECT("1:"&ROWS(Data)))),ROW(INDIRECT("1:"&ROWS(Data)))))}

The second formula is a single-cell array that is entered into cell F4 and copied down the range F4:F12. The formula in cell F4 is:

{=INDEX(DataX,SMALL(IF(Data=G4,ROW(Data)-MIN(ROW(Data))+1),COUNTIF($G$4:G4,G4)))}

As stated above, because this is a single cell array it must be copied through the range F4:F12.

With both formulas properly entered, the helper columns now reflect the original data excluding zeros as shown below.

image

Conditional formatting can be applied to the helper columns to get rid of the errors (#NUM!). In the conditional formatting dialog box below, I've set the font color to match the background of the spreadsheet (white) if the formula returns an error. The result is to hide the error value.

image

At this point a simple bar chart can be created using dynamic formulas based on the helper columns. Start with creating two more named ranges. In this example a named range called "ChartData" is created that contains the dynamic formula which serves as the data source for the chart. That formula is:

=OFFSET(Sheet1!$G$4,,,COUNT(Sheet1!$G$4:$G$12),1)

The defined name dialog box now looks like this:

image

The second named range is called called "ChartDataX". It contains a dynamic formula which serves as the X-Axis source for the chart. That formula is:

=OFFSET(Sheet1!$F$4,,,COUNT(Sheet1!$G$4:$G$12),1)

The defined name dialog box now looks like this:

image

In this example the workbook is called CNZ.xls. The source for the bar chart references the named ranges "ChartData" and "ChartDataX" as shown in the Chart Source Data dialog box below:

image


References:
  • Explanations of how to create array formulas as well as the ROW and INDIRECT functions can be found in John Walkenbach's book titled Excel 2003 Formulas.
  • Jon Peltier provides a series of links to sites that show how to build dynamic charts.
  • Andy Pope provides an example of a dynamic scrolling chart.
  • An explanation of how to build dynamic charts is also included in John Walkenbach's book titled Excel Charts.

Posted on Saturday, May 19, 2007 | Comments (1) | Permalink
Comments

I found this to be wonderful and it worked.  My question:  is there anyway to do this with two data columns instead of one and to make them match up?  I tried to add another series but the numbers were off as were the people.  Might not be possible…

Posted by .(JavaScript must be enabled to view this email address)  on  02/19  at  08:22 PM
Page 1 of 1 pages

Comment Entry Form

User Information

Name: (Required)

E-Mail Address: (Optional)

Location: (Optional)

Web Site Address: (Optional)

Comment Formatting Reference
Add VBA Code:
<pre>some code here</pre>
Linking:
[url]http://www.example.com/[/url]
[url=http://www.example.com/]my site[/url]
Text Formatting
[size=4]Some larger text[/size]
[color=green]Some green text[/color]
[b]Some bold text[/b]
[i]Some italic text[/i]
Enter Comment Below

Personalization Options
Remember my personal information
Notify me of follow-up comments?

Next entry: Name, Hide, and Show Embedded Charts

Previous entry: Microsoft Knowledge Base

<< Back to main

Statistics

  • Total Entries - 136
  • Current Viewers - 25

Categories

Entries by Day

Jul - 2010
S M T W T F S
27 28 29 30 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Recent Comments

Syndicate