Chart the Last 12 Months Dynamically.You want to create a chart that shows the last twelve months of data. But how do you create a chart from the latest data in a range that grows, without having to manually update the source data range every month? Here is an example showing how to construct a dynamic chart to update automatically. The DataStart with the following sample data in the worksheet named Sheet1:
Normally you'd select the data and make a chart using the chart wizard. But that chart wouldn't be dynamic, and you'd be stuck performing monthly maintenance on it. Define the Dynamic NamesTo make a dynamic chart, you first have to define some dynamic range names. Press Ctrl-F3 (or go to the Insert menu, choose Names..., then Define) to open the Define Names dialog. In the Name box type chtLen, and in the Refers To box enter =Sheet1!$D$2. The range name chtLen refers to the length of the chart series (the number of months in D2). Click Add. Type chtCats in the Name box. In the Refers To box, enter the following formula and click Add. Instead of typing this long expression, just copy it from this page and paste it into the Refers To box by using Ctrl-V. =OFFSET(Sheet1!$A$1,COUNTA(Sheet1!$A:$A)-1,0,-MIN(chtLen,COUNTA(Sheet1!$A:$A)-1),1) This defines the range in column A that contains the last twelve months (categories). Check Excel's help for information about OFFSET and other worksheet functions. Type chtValA in the Name box, then enter (or Copy-Paste) =OFFSET(chtCats,0,1) in the Refers To box, and click Add. Type chtValB in the Name box, then enter =OFFSET(chtCats,0,2) in the Refers To box, and click Add. These are the monthly values we want to track. Finally, click OK to close the Define Name dialog box. Note for Excel 2007 users: This technique will fail if your Names begin with the word "Chart". Use names like ChtValues instead of ChartValues. Create the ChartNow select a blank cell somewhere and start the Chart Wizard. In step 1 choose a chart type(this example uses a clustered column type). In step 2, click on the Series tab, then click Add to add the first series. Click in the Name box, then select cell B1 (it will show =Sheet1!$B$1). Replace the contents of the Values box with =Sheet1!chtValA. Click in the Category Labels box and enter =Sheet1!chtCats. Now click Add to add the second series. Click in the Name box, then select cell C1. Replace the contents of the Values box with =Sheet1!chtValB. The Category Labels box already contains =Sheet1!chtCats. The resulting chart looks like any 12-month picture of the data: Dynamic BehaviorNow fast-forward six months. The following table has been added to the worksheet:
The chart has updated with no further intervention on your part, spanning the twelve months from July to June. There is a trick in the definition of chtCats which avoids errors when the data range is less than 12 months long. If we were certain that the range would always have at least 12 rows of data (chtLen), we could have used: =OFFSET(Sheet1!$A$1,COUNTA(Sheet1!$A:$A)-1,0,-chtLen,1) But if the range is shorter, the OFFSET formula would refer to rows before row 1. The term MIN(chtLen,COUNTA(Sheet1!$A:$A)-1) takes the actual length of the range if it's less than chtLen: =OFFSET(Sheet1!$A$1,COUNTA(Sheet1!$A:$A)-1,0,-MIN(chtLen,COUNTA(Sheet1!$A:$A)-1),1) Delete all but the first nine months of data. The chart captures the shortened range without a snag. Here are more Dynamic Chart resources on this web site:
For a partial list of internet links to dynamic charting, click here. Alse see Dynamic Charts on the PTS Blog. |
Peltier Technical Services, Inc.Excel Chart Add-Ins | Training | Charts and Tutorials | PTS BlogPeltier Technical Services, Inc., Copyright © 2017. All rights reserved. |