1. Skip to navigation
  2. Skip to content
  3. Skip to sidebar

Charts are a great way to explore data. Here is some American baseball data showing player salaries over a five year period.

Baseball salaries by team over time

Charting this data with a line chart would allow us to see trends in salaries by team. However, when we use Excel’s default chart, we get something that looks like this:

Excel’s default multiline chart

That’s quite a mess. It would be a lot easier if we could create one chart for each row.

The OFFSET function is going to help. In its simplest form the OFFSET function works like this:

OFFSET(anchor, rows from anchor, columns from anchor)

That is, OFFSET will start with the anchor cell, go down a number of rows from that anchor and over a number of columns and return the value it finds.

OFFSET function

We can use the OFFSET function to create cells that pull a single row of data out of the table dynamically. We create a new row atop of our data and create a series of OFFSET functions that all rely on a single cell (the big yellow one) for their row offset. So changing one cell will pull different rows of data into our fixed location.

Creating a dynamic row that doesn’t move

Now, chart the data that doesn’t move.

Charting the dynamic row

After fixing the chart, we’d like to make it easy to change the value in the big yellow cell.

We can use Excel Forms to build a lightweight user interface. Bring up the Excel forms toolbar by rightclicking on any toolbar and choosing Forms. Place a scrollbar beside the chart.

Excel Forms

Right clicking on the scrollbar allows you to Format Control. Link the control to the cell that is controlling all the row offsets. Now, moving the scrollbar will update the chart.

Chart with scrollbar
Selecting Format Control
Formatting the scrollbar control

Now, the scrollbar controls the chart. Here is the baseball spreadsheet for you to play with: Baseball_offset.xls Have fun!

On the way to 100 charts

Note: this post is adapted from a presentation I gave at eMetrics 2007 in San Francisco.

Topics:
, , ,
  • derek

    Very nice, but don’t be too quick to discard the value of all the other lines. Why not present them as in the original mess, but in the thinnest strokes of identical lightest grey, against which your chosen line can stand out in bold blue?

  • http://juiceanalytics.com Chris Gemignani

    Thanks, Derek. Man, sometimes the posts just write themselves.

    I’ve used the technique you describe and it can work very well indeed. In the past, I’ve done this this VBA, but probably a clever use of offset could make this work without the need for all the coding. We’ll write this up sometime. Thanks!

  • derek

    Clever use of offset? I added the whole lot in with Add Data, turned one line grey, used F4 and the up-arrow key to repeat thirty one times (you soon get into the rhythm :-) ) brought the blue offset line back up to the top of the stack (“Series 33″) and finally, fixed the chart title link, that got destroyed by the Add Data stage. See example

    Were you thinking that the grey line representing the selected data must be excluded? No need, it’s hidden under the blue line.

  • http://juiceanalytics.com Chris Gemignani

    Beautiful. For the record, I was going to hide the grey line under the blue too. ;-)

  • Madan

    Brilliant! I’ve been struggling with understanding the offset function for weeks, this made it finally make sense.

  • pg

    Beautiful! And can I copy or export this little lovely Format Control box into PowerPoint, say?

  • derek

    Sadly no. If you want to go to a live Excel application in the middle of a presentation, I suggest you design a hyperlink (Ctrl-K in Powerpoint) to a file that you already have open in Excel, and the Excel formatted to be as blank as possible (Full Screen display, Tools>Options>View set to remove all possible Excel features like gridlines and column headers etc.)

  • http://www.accessionmedia.com Josh

    Yet again…SWEET tip. Thanks Chris.

  • http://www.blog.methodsinexcel.co.uk ross

    Yeah real nice,
    The only thing i might do differently is place the scroll bar next to the data list, rather than the chat, might be a bit more intuative? line the way the lines is highlighted, good stuff.

  • Jeff

    I might be missing something but I cant figure out who you get the chart title to change dynamically with the selection? I can trick it by labeling the series with the team name (and repositioning) but you have me stumped on the header function?

  • Darrell

    Jeff, I know what you mean, its tough to now what team you’re selecting. This is a minor usability issue, and not what Chris was attempting to demonstrate. The Offset function is mucho powerful for selecting different data sets in a big data table.

    It would be better to have the user select from a list of the team names, rather than clicking sequentially through each one. This can be done with either a data validation, combined with a match() function, or a pick-list form. Incidentally I often use the cell underneath the pick-list form so it doesn’t show when viewed / printed.

    Another Tip:
    I noticed that the Yankees 2005 number exceeded the manually set scale (223 vs. scale max of 200). This is a nuisance to detect/correct on one or two charts and a maintenance hassle if you have many charts.

    One way that I found to have Excel automatically set a uniform scale among different data sets is to use the Min() & Max() functions over the entire data set and then Plot a fake data series (or two) with the min & max data.

    In order to hide the fake data from displaying, you format the fake series by setting the Line & Marker to None (Format Data Series, Pattern: Line: None Marker: None). and then set the Value Axis Scale set to Auto. Excel accounts for the min / max data series when it calculates the Auto Scale setting and will always choose the same scale (from what I tested).

    In this manner, the data will have a uniform scale among the different teams, and you don’t have to worry about data exceeding the chart scale, or the Arizona Diamond backs looking equally profitable as the New York Yankees :)

  • Darrell

    Jeff, a correction. I don’t think I answered your question: you wanted to know how the chart title changed.

    When you chart something in Excel, Excel guesses the chart title by picking the name of the first data series (the first argument of the first data series). In this case it is the
    ‘Dynamic Charts’!$b$4 that instructs Excel what to call series One and the chart title.

    The series in the spreadsheet defined as:
    =SERIES(‘Dynamic Charts’!$B$4,’Dynamic Charts’!$C$3:$G$3,’Dynamic Charts’!$C$4:$G$4,1)

    =Series(Arg1, Arg2, Arg3, Arg4)
    where:
    Arg1 is Series name, and default chart title if its Series #1
    Arg2 is the names assigned to the category / X-axis
    Arg3 is the data you want to chart, and
    Arg4 is the number of the series

  • darrell

    Jeff,

    I was looking at Chris’s file, not Derek’s. I know the trick Derek used.

    This tip works for any of the text boxes in a chart (that includes Chart Title, or even individual Data Labels). You can customize the text, either by overtyping it (Select box, hit F2 and type text), OR specifying a cell link.

    To do this is a minor trick. You select the box, pause, Hit F2 and type the cell link into the formula box. I find it easiest to use the formula bar, rather than the text box. If you do it wrong, it creates an extra text box in the middle of the chart, if you do it right, the text is whatever is in the cell.

    In this case, he selected the Chart Title, did the F2 – edit trick, and entered “=’Dynamic Charts’!$B$4″ .

    Note that you cannot do a formula in the text box, you can only do a cell reference or a named range to a single cell. BUT the cell you reference can use any combination of formulas. Its especially useful to use concatenate() to incorporate figures or amounts into a title or data label.

    Example:
    in cell $b$4, you could enter
    =”New York Yankees – 5Yr total $”&sum(c4:g4)

    and the chart will update have the title:
    New York Yankees 5Yr Total $865.936

    Better formatting:
    =”New York Yankees – 5Yr total $”&fixed(sum(c4:g4),0)&”MMs”
    New York Yankees 5 Yr Total $866MM

    That type of simple stuff wows my boss everytime :)

  • http://www.supportanalytics.com Tony Rose

    Impressive! There has been a lot of great comments to help improve and build upon Chris’ post. I do think there is some value to showing all of the basic line charts grouped together so you can visually see the differences in one glance, like Derek’s example. Also, you may add a 5-year average column to sort from highest to lowest versus alpha. Keep up the great work!

    Anyone else shake their head at the Yankees payroll?

  • derek

    A recent discussion referred to in Stephen Few’s blog led me to the pdf he wrote (because he couldn’t put the graphics he needed to refer to in the comments box) about using Spotfire to create the (stupidly named, but actually quite clever) “parallel coordinates” graph type. This has inspired me to think of using Chris’s baseball spreadsheet as the basis for a “Poor Man’s Spotfire” using Excel.

    I’ve made a start creating a view that “brushes” (fancy word for “selects”) “The Highest/Lowest N baseball salaries in the year nnnn” and highlights those in thick blue against the thin grey of the rest of the teams. I used INDEX/MATCH instead of OFFSET. The next thing I want to do is try to highlight the “N teams whose pay profile looks most like Team T”, using a least-squares fit.

    When and if I make it a little more robust and add some more of the Spotfire functions Few uses in his article, I’ll post it to Chris. Or y’all can start picking up the challenge on your own. How far can you push Excel to mimic exploratory data analysis with parallel coordinates and brushing? :-)

  • http://juiceanalytics.com Chris Gemignani

    Great idea, Derek. We were playing around the other day with another concept in Spotfire “heatmaps” for displaying tabular data. These turn out to be very easy to recreate in HTML tables. We’ll post a solution sometime soon.

  • Fumiko

    Thank you so much for sharing great ideas as always. It’s clean and elegant, and overcomes the mess we could easily fall by using standard chart alternatives provided in original Excel.

    I already have a data that I could use this solution. Once again,thank you for sharing this tip with us!!

  • craig

    how can you switch the x and y axis when using Add Data?
    thanks

  • Michael

    How do you dynamically highlight the row item as the graph changes?

  • http://juiceanalytics.com Chris Gemignani

    Michael, I use a formula-based conditional format that looks roughly like: “ROW()=$A$2″

  • http://www.bullindia.com Sasikumar

    It is really helpful to us to make a good presentation. It is very intresting also. let me know these type of other features in excel graphs

  • Mark

    NICE IDEA!!! This would be REALLY useful for comparing multiple scenarios, which would mean I could select up to say 3 or 4 to plot at the same time. I will give that a shot, and thanks for the great start.

  • N Shivkumar

    Excellent tip as to how to use control. Thanks a lot and keep posting new ideas.

  • derek

    Jon Peltier has created a parallel coordinates tool in Excel here, to explore quarteback preformance data. The two chart controls choose which player to highlight in red and which in blue. the rest of the players are pushed into the background as gray lines.

  • Randy

    This is great. Is their a way to use the same scrollbar on multiple figures. Specifcally if I want to pictures side by side that flip as I scroll.

  • andrew

    I never usually comment on stuff like this (I know, I should)…but this is AMAZING. Thanks!

  • Andrew

    Very useful – thanks for sharing this.

  • Adam

    This is helpful. I am trying to do something similar, and maybe someone here can help. I would like to create a bar + line graph and have the date range (x-axis) be controlled by a drop-down menu. Ideally, I would like to be able to select a beginning date and an end date and have the graph adjust automatically. Is this possible?

    Thanks

  • Bill

    This is truly extraordinary. I will build from this and wow everyone. Thank you for sharing the file.

  • ray

    great and simply outstanding!!!

  • Tim

    This is great!! This is such a time saver. One question, how do you auto scale the axis in case you have a very wide range of data. For example in one graph I need a to scale to 200, in the next one I need to scale to 5000.

    Thanks and keep up the great work you’re doing.

  • Sean

    It sounds like an amazing concept, however, whilst using Excel 2003. It seems that the ‘Control’ tab on the ‘Format Control…’ window is missing. Would you be able to provide a sample excel document so that I could look at the VB code behind the scroll bar? or provide the code on here?

    Many thanks!

  • Sean

    Oops, I didn’t see the sample document mid way down the page!

    Many thanks!

  • Yan

    Love it! Very easy to understand. Thanks!