Excel chart dynamic range-selection - excel

I have a client that has a simple yet complicated request for an excel sheet setup, and I can't for the world thing of where to start. I'm drawing a blank.
We have a data range. Example:
Quarter Data
2010Q1 1
2010Q2 3
2010Q3 4
2010Q4 1
I have a chart built on top of that. Change data, chart changes, protect worksheet to keep other idi... er... users from changing old data. Simple.
What I want to have happen: When I add the next Q1 below Q4, the chart "automagically" selects the most recent 4Q. So when I update the data to:
Quarter Data
2010Q1 1
2010Q2 3
2010Q3 4
2010Q4 1
2011Q1 7
The chart will show data for the last 4 quarters (2010Q2 thru 2011Q1). The goal being: keep "old" data on the same sheet, but have the charts update to most recent quarters.
I'm thinking: "fixed" data locations, reverse the data (new data at top), and just insert row each new quarter:
Quarter Data
2011Q2 9
2011Q1 7
2010Q4 1
2010Q3 4
2010Q2 3
2010Q1 1
But this will involve a lot of changes to the already existing excel sheets and I was hoping that there may be an easier/better "fix".
EDIT:
#Lance Roberts ~ Running with your suggestion:
- Little more detail... The data is setup such that the column information is in A, but data for multiple tables are in B+. Table 1 is B/C. Table2 is D/E. Etc.
- Data is also on a different sheet than the tables.
Going by: This Offset Description, what I've tried doing is adjusting similar to such:
NAME FORMULA OFFSET(range, rows, columns, height, width )
DATA0 =OFFSET('DATASHEET'!$A$2, COUNTA('DATASHEET'!$A:$A - 8, 0, 8, 1)
DATA1 =OFFSET('DATASHEET'!$A$2, COUNTA('DATASHEET'!$A:$A - 8, 1, 8, 1)
DATA2 =OFFSET('DATASHEET'!$A$2, COUNTA('DATASHEET'!$A:$A - 8, 2, 8, 1)
Goal being to tie the length/location for B/C/etc data to A. So if I add a column on A, stuff tied to Data1/2 adjust accordingly (or 3/4/5/etc, which are different charts on different sheets
)
I want data cells to be picked by the first row, and then an offset number to get data x columns over. Variations on the formula don't seem to be working.
1 issue I haven't solved yet: the data is not aligning properly:
"Data" is always, last column under 2nd to last Quarter. Last quarter is always empty. Data is shifting to the right (in this example, under 3Q10 - NOT under the correct column. 11 should be under 4Q10. 9.5 should be under 2Q10).
I know I'm getting something simple wrong...
Seems to be working. First thing I had to change was CountA - 9 (not CountA - 8). Next was the "column offset" (0, 1, 2, 3,...). Also split some stuff up to make it more compartmentalized (I do have to train someone else how to do this for her reporting needs).
Thanks Lance :)

If the chart is on the same sheet as the data:
Name the first cell of the data (A2) as a named range, say TESTRANGE.
Created a named range MYDATA as the following formula:
=OFFSET(TESTRANGE, COUNTA($A:$A) - 5, 0, 4, 2)
Now, go to the SERIES tab of the chart SOURCE DATA dialog, and change your VALUES statement to:
=Sheet1!MYDATA
Now everytime you add a new row, it'll change the chart.

I know this is an old question, but I wanted to share an alternative that may be easier.
Change your Quarter-Data range to an Excel Table. Select the range, and press Ctrl+T. In the Insert Table, make sure the correct data range is selected, and that My Table Has Headers is checked, and press OK. This converts the simple range into a special data structure with magical properties.
Then make a new range which links to the last four rows of this table, and create a chart based on this new range. This is illustrated below. The table is the specially formatted range in A1:B9 (you can choose a less in-your-face style), and the plotting range is D1:E5.
The formulas in cells D2 through D5 are below. Copy D2:D5 and paste into E2:E5 to complete the formulas in our plotting range.
D2: =INDEX(Table1[Quarter],ROWS(Table1[Quarter])-3)
D3: =INDEX(Table1[Quarter],ROWS(Table1[Quarter])-2)
D4: =INDEX(Table1[Quarter],ROWS(Table1[Quarter])-1)
D5: =INDEX(Table1[Quarter],ROWS(Table1[Quarter]))
Table1 is the name assigned to the Table, and Quarter is the name of the first column of the Table (and also the column header). You don't need to type all this, just select the column in the Table. As the Table expands or contracts, Table1[Quarter] keeps track of the changes.
Now add a new data point. The Table expands, and our little staging area in D1:E5 links to the new last four rows of the table.
And as we add years worth of data, the formulas and the chart keep up.

Related

ungrouping Excel data saved as an Outline as a pivot table

I do not know if it is possible to do what I want to achieve in Excel, but I have the data that is generated in the Outline (let's assume: on the left side of the screen I have a "plus", if I press it, I have another "+" and I get to the next detailed data.
The problem is, when I ungroup it all, I have every item in column "A" and I can't make it into a PivotTable.
What I mean?
Example (you can see it in the photo).
1 "plus" - country:
[![enter image description here][1]][1]2 "plus" - city:
3 "plus" - brand of items sold
4 "plus" - exact equipment from this brand
When I ungroup it, everything is in one column and it should be - respectively - 1 "plus" - column A, 2 "plus" - column B, etc.
Is there any possibility to ungroup it according to the "pluses".
I hope there is any sollution...
Thanks
See https://www.mrexcel.com/board/threads/calculating-outline-levels-in-excel.227279/#post-1112028 copied here:
Select cell A1 of the sheet,
Do menu command Insert/Name/Define, and create a name called DetailLevel, with a formula ( in the Refers To box ) of:
=GET.CELL(28,Sheet1!A1)
( alter the sheet name Sheet1 to whatever your sheet is called )
Now in any blank column of the sheet type the formula =DetailLevel and copy down.
That will give you 1 for no indent, 2 for level 2, 3 for level 3
bring that along as data column to create pivot table

Excel: How to format a column graph so that it automatically adds new columns when new data is added?

A bit of background: I have a table which by using a combination of vlookup and index, goes through my main dataset and pulls out each row of data for a given month (in this case March). Each month will have a maximum of 15 entries, but may have less.
The image below is an example of the table for the month of March, which currently has 4 entries.
I want to create a column graph which is sourced from this table, that formats in a way such that if there is:
4 entries, it shows 4 evenly spaced columns
5 entries, it shows 5 evenly spaced columns
etc...
However, when I create this graph using the two yellow highlighted columns of data, I get 4 columns (in the graph) squashed over to the left side, and a whole bunch of blank space, as seen below:
Is there a way that I can create a graph that looks like the graph on the left, and that will add in new columns automatically as data appears in the table, without looking like the graph on the right?
Thanks
You could automatically updated your graph data ranges using VBA.
For example if your data range is in columns A and B of Sheet2 and your graph is Sheet1 you could use the following code:
Sub UpdateRange()
Dim LastRow As Long
Dim RngCount as Range
Set RngCount = Sheets("Sheet2").Range("A1:A10")
LastRow = Application.WorksheetFunction.CountA(RngCount)
Sheets("Sheet1").ChartObjects("Chart 1").Chart.SetSourceData Source:=Sheets("Sheet2").Range("A1:B" & LastRow)
End Sub
Graph with old data:
After data was added and the macro was run:

Excel formula - fixing cell reference across multiple worksheets

This is a question for Excel. I have to create similar tables in several worksheets. But the tables are not matched up in terms of the row numbers. For example, table in worksheet one starts on row 48; table in worksheet two starts on row 35, etc. Each table refers to a cell that is 3 rows above the table starts and needs to be fixed for the length of the table. So, in table in worksheet one, the formula needs to refer to cell M45 (three rows above 48); in table in worksheet two, the formula needs to refer to cell M32 (three rows above 35); and so on. If it were just one worksheet, I know that I could fix 32 and refer to M$45. But I do not know how to automate it for the problem described above. The formula I need to automate is:
IF(SUM($L49:$L$61)>=M$45,0,MIN($L48,M$45)).
M$45 needs to be M$32 in worksheet two when I copy the formula over from worksheet one to worksheet two. The other references will also need to be modified accordingly. But once I know how to do one, I can take care of the rest.
Would appreciate any help you can provide.
If you use the following inside the table,
=OFFSET([#Headers], -3, 0, 1, 1)
The formula will adjust to show the table name as in,
=OFFSET(Table1[#Headers], -3, 0, 1, 1)
Copying the table will adjust the internal formula to the new table's name. e.g.
=OFFSET(Table2[#Headers], -3, 0, 1, 1)

Excel manipulates invisible cells in Filtered Range

I have a large table that contains a large data. Most of the time when I apply a filter to it i can manipulate and edit the filtered data with no problems. However sometimes(every 200th time perhaps...) when i select filtered range and try to paste in the selection some text - it seems like it has done the job but when I unfilter the table, the range that was edited is the range as it wasn't filtered at all.
Example:
my data is A1:A10
the filtered range is the cells A1 and A10,
when I select the filtered range and paste a text, occasionally the whole A1:A10 range is changed.
Anyone faced this issue?
the consequences are disastrous.
How will i avoid it in the future.
Thanks!
Ok I figured it out.
When the data is filtered, I select cells and want to apply some changes to it - what happens is that excel defines the rows range for manipulation as "upper row in selection to bottom row in selection":
the problem is that sometimes the row indexes are not consecutive(common issue when the data is not logically ordered in the first place) and excel treats the whole range in between the visible selected cells as the range for manipulation TOO.
It hapened to me occasionally only because my data is more or less ordered.
Example: a small table of numbers
**nums**
1
2
3
4
5
3
6
if i filter the nums table to show only 3s
it will show me this:
**nums**
3
3
when i select these two cells by dragging from one 3 to the other, paste the number 0 and unfilter the table back, the result will be
**nums**
1
2
0
0
0
0
6
because the cells inbetween the visible cells were in selected range too.
To prevent it, the solution is as Lior suggested:
Find & Select --> Go to... --> Visible cells only.
After you select the column you want to edit use select visible cells only.
in the link there is an example of the copy you can use the same for the paste.
http://office.microsoft.com/en-001/excel-help/copy-visible-cells-only-HA010244897.aspx

Excel - calculating durations of time data spread across multiple rows

I have a spreadsheet with a dataset of a number of transactions, each of which is composed of substeps, each of which has the time that it occurred. There can be a variable number and order of steps.
I'd like to find the duration of each transaction. If I can do this in Excel then great, as it's already in that format. If there isn't a straight-forward way to do this in Excel, I'll load it into a database and do the analysis with SQL. If there is an Excel way round this it'll save a few hours setup though :)
A simplified example of my data is as follows:
TransID, Substep, Time
1, step A, 15:00:00
1, step B, 15:01:00
1, step C, 15:02:00
2, step B, 15:03:00
2, step C, 15:04:00
2, step E, 15:05:00
2, step F, 15:06:00
3, step C, 15:07:00
3, step D, 15:08:00
etc.
I'd like to produce a result set as follows:
TransID, Duration
1, 00:02:00
2, 00:03:00
3, 00:01:00
etc.
My initial try was with an extra column with a formula subtracting end time from start time, but without a repeating number of steps, or the same start and end steps I'm having difficulty seeing how this formula would work.
I've also tried creating a pivot table based on this data with ID as the rows and Time as the data. I can change the field settings on the time data to return grouped values such as count or max, but am struggling to see how this can be setup to show max(time) - min(time) for each ID, hence why I'm thinking about heading to SQL. If anyone can point out anything obvious I'm missing though, I'd be very grateful.
As suggested by Hobbo, I've now used a pivot table with TransID as the rows and twice added Time as the data. After setting the field settings on the Time to Max on the first and Min on the second, a formula can be added just outside the pivot table to calculate the differences. One thing I'd been overlooking here is that the same value can be added to the data section more than once!
A follow-on problem was that the formula I add is of the form =GETPIVOTDATA("Max of Time",$A$4,"ID",1)-GETPIVOTDATA("Min of Time",$A$4,"ID",1), whici doesn't then increment when copying and pasting. Solutions to this are to either use the pivot table toolbar to turn off GETPIVOTDATA formulae, or rather than clicking on the pivot table when selecting cells in the formula, type the cell references instead (e.g. =H4-G4)
In your formula "GETPIVOTDATA("Max of Time, $A$4, "ID", 1) - GETPIVOTDATA("Max of Time, $A$4, "ID", 1)' the cell references are addressed between the symbol "$'. For example $A$4. When the cell references having $ symbol and you copy the formula to other cell then reference cells are not updated automatically. Hence you get the same type.
Perhaps you modify the formula as follows and then copy the formula to other cells. The formula should be like:
"GETPIVOTDATA("Max of Time, A4, "ID", 1) - GETPIVOTDATA("Max of Time, A4, "ID", 1)".
Thanks.
You were on the right lines with pivot tables. Drag in TransID as a row field then drag in two copies of Time as data fields in the pivot table; right click on each and specify Min as the summarization function for one and Max for the other. To the right of the pivot table add a formula to calculate the difference.
alt text http://img296.imageshack.us/img296/5866/pivottableey5.jpg
"Looks good, the only problem I have is that the formula I add is of the the form =GETPIVOTDATA("Max of Time, $A$4, "ID", 1) - GETPIVOTDATA("Max of Time, $A$4, "ID", 1). When I copy that to the cells below, the 1 doesn't update to 2, 3 etc so they all show the same time. – Kris Coverdale "
Use this button on the pivot table toolbar to switch GETPIVOTDATA formulae off.
alt text http://img117.imageshack.us/img117/9937/pivottabletoolbarjn3.jpg
Maybe something as simple as a query like this.
SELECT TransID, DateDiff(mi, Min(Time),Max(Time)) AS Duration
FROM MyTable
GROUP BY TrandID
In excel:
A B C
1 1, step A, 15:00:00
2 1, step B, 15:01:00
3 1, step C, 15:02:00
4 2, step B, 15:03:00
5 2, step C, 15:04:00
6 2, step E, 15:05:00
7 2, step F, 15:06:00
8 3, step C, 15:07:00
9 3, step D, 15:08:00
11 1, =max(if($A$1:$A$9=$A11,$C$1:$C$9,"")-min(if($A$1:$A$9=$A11,$C$1:$C$9,"")
12 2, =max(if($A$1:$A$9=$A12,$C$1:$C$9,"")-min(if($A$1:$A$9=$A12,$C$1:$C$9,"")
note: formulas are array functions so press ctrl-shift-enter after editing them.
To add to Kibbee's post, in reference to the comment, you can use ADO with Excel:
'From: http://support.microsoft.com/kb/246335 '
strFile = Workbooks(1).FullName
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
& ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.Open strCon
strSQL = "SELECT TransID, DateDiff('n', Min([MyTime]),Max([MyTime])) AS Duration " _
& "FROM [Sheet1$] GROUP BY TransID"
rs.Open strSQL, cn
'Write out to another sheet '
Worksheets(2).Cells(2, 1).CopyFromRecordset rs
EDIT: I have corrected some errors in the original post and changed the name of the time column to MyTime. Time is a reserved word in SQL and causes difficulties in queries. This now works on a very simple test.
Sometimes it is possible to do something once in Excel far more easily than it is to do something repeatably.
Assuming you are just trying to get the answer once or twice, and then throw away the spreadsheet (as opposed to run it every night, or give it to someone else to run), here's how I would do it.
I assume your raw data is in columns A, B and C, with headings in row 1, and data starting in row 2.
Sort the table by TransId as your primary key, and Time as your secondary, both ascending. (The following won't work if this isn't done.)
Add a new column, D, titled Duration with a formula that like this (Excel formulae haven't formatting or comments; I have added those to help explain, but they need to be stripped out):
=IF(B2=B3, // if this row's TransId is the same as the next one
"", // leave this field blank
C3- // else find the difference between the last timestamp and...
VLOOKUP( // look for the first value
A2, // matching this TransId
A:C, // within the entire table,
3) // Return the value in the third column - i.e. timestamp
)
Now the data you want is in column D, but not in the format you want.
Select Columns A-D and copy them. Use Paste Special to copy the values only into a new worksheet.
Delete column B and column C in the new worksheet, so all is left is TransID and Duration.
Sort by Duration, to bring all the rows with values next to each other.
Sort only the rows with values by TransId.
Voila, and there is your solution! Hope you don't need to repeat this!
p.s. This is untested

Resources