How to Make An Excel Graph Without Hardcoding the Data Range - excel

I have a graph getting data from a simple 2-row date and production amt. associated with that specific date. However, we are constantly adding more and more rows to this and I would like the graph to be self-updating every time we add more rows instead of having to change the formula's data range every single time we update the sheet.
Right now the formula we're using for the graphs is:
=SERIES(,'PRODUCTION SITE A'!$A$4:$A$125,'PRODUCTION SITE A'!$B$4:$B$125,1). Here's an example spreadsheet on Google Sheets to make it more visible what exactly I'm doing.

You can graph and chart dynamic ranges by putting the data in a Formatted Table. Highlight everything from [Date - Amt Produced] down to the last row of data (not including Total), and click "Format As Table".
Now, when you add lines to the data, the Table will expand - as will the graph! If it does not automatically expand, you can manually expand the table (and thus the graph) by simply clicking inside the Table, then clicking "Resize Table" in the Table Tools>Design tab.
Notably, if there is a blank line directly below the Table, entering data there will cause the Table to automatically expand its size to include the new data. If you have a Total row directly below the Table, you may have to "Insert" a row above the Total row, then enter data. My suggestion would be to move the Total somewhere else (perhaps above the Table?), so that you can simply type in the next blank line below the Table and have the Table adjust its size for you without the Total getting in the way.

Related

Generate summary gantt chart from detailed activities

I want to create a gantt chart summary that shows a person´s whole "busy" and "free" schedule by day and in a single row, from a detailed gantt chart with a list of activities of different people in multiple rows.
Basically go from this:
To this: (which I created Manually)
To be able to give a summary of people´s shifts free time between activities.
Right now I´m just using this formula to compare the start and end date in each row and produce a "1" if the condition is True, then I just condition formatted the whole Gantt cells.
=IF(AND(Q$8>=$N12,DAY($K12)<>DAY($J12)),1,IF(AND(Q$8>=$N12-0.00001,Q$8<$O12-0.00001),1,""))
I have no idea how to start. I was thinking of doing the nest things:
Create a table of the names of all the possible people to be added in the gantt chart.
Program the macro to create a new sheet with the same template.
Program a loop which starts iterating with each person´s name:
For each person´s name which exists in the gantt chart to be summarized, start creating new rows per each day they have activities scheduled (I can´t figure out yet how I´d iterate through this).
Within the each person´s loop, start iterating each row on the original sheet, evaluating each start and end date´s and pasting on the new sheet´s current person´s current day row a "1" if the condition was true in the corresponding hours.
Loop until all individual activities of each person are finished.
Continue with next person.
I´d like to know if this is the logical way to go and if you have any pointers or similar code to recycle, I am not proficient in VBA and Excel macros.
Not sure if I understand properly, but it looks like you got a set of multiple records where you store the times In and Out of each worker, several rows for each worker.
And based on that, you would like to resume data, one row per worker, highlighting start and end time of each worker, but all in a single row.
I made a fake dataset like this:
I added 2 extra columns (you can even hide them if you don't want to see them)
Field START TIME got this formula:=B2-INT(B2)
Field END TIME got this formula: =C2-INT(C2)
In Excel, Dates are integers values and times are decimal values. I used both formulas to get only the decimal part of each start and end.
All this data is a table object named T_WORKERTIMES. I made a table object so if you add new records, the Gant Chart will autoupdate.
Then I made a simple (kind of horrible) Gant Chart:
The formula I've used in H2 and drag is:
=COUNTIFS(T_WORKERTIMES[Worker];$G2;T_WORKERTIMES[start time];"<="&H$1;T_WORKERTIMES[end time];">="&H$1)
Actually, all my data is in same sheet:
I added 2 Conditional Formating Rules to highlight cells in green/white if the result of the formula is 1/0.
Also, working with times sometimes can be hard, because decimals. 0,677083333335759 means 16:15. But 0,6770833333333333 too, so in Gant Chart I rounded up headers to 6 decimals.
My formula in H1 is =ROUND(7/24;6)
My formula in J1 and drag to right is =ROUND(H1+1/24/4;6)
So now everything works fine. Please, notice in worker 1, there is no activites from 07:00 to 08:00. So I add a new row with that data and everything updates:
I've uploaded a sample yo Google Drive you can see the formulas and hope you can adapt this to your needs.
https://drive.google.com/file/d/1KOuCAYsmlY9gfNUCUhIrihXu-tJz-K7t/view?usp=sharing
Biggest issue here is the decimal part of times, to make sure they fit the Gant Chart. An easy solution would be substracting just 1 minute to start time column (calculated, you can hide it) and sum 1 minute to end time column (calculated, you can hide it).
Hope this can guide you in your project.
It looks like you are trying to extract unique records per person and day to get a person/day summary of time availability but also want it to be automated as you add more people and days.
I was able to do this with a combination of powerquery and a pivot table. When new persons/dates are added or changed the report will update but you will need to refresh using CTRL+ALT+F5
you want to highlight your entire report or an area as big as you think it will get. While highlighted you will then utilize named range feature under FORMULAS tab -> DEFINED NAMES ribbon -> DEFINED NAME dropdown. We could name it REPORTAREA or something like that.
Make sure you change the conditional format formula in report to show 0 instead of "" so this can work properly
2 go to DATA tab -> GET AND TRANSFORM ribbon -> From other sources -> Blank Query.
This will open the power query editor as a blank query
3 In the formula bar type =Excel.CurrentWorkbook() case sensitive is important
4 From there you will see CONTENT and NAME column.
In the NAME Column select the drop down and go to TEXT FILTERS -> Equals... Type in the name of your named range so the query does not pick up anything else on accident.
5 Remove the NAME column by right click selecting it and then remove.
6 you will notice the CONTENT column has two curved arrows pointing left and right instead of straight down like you are used to in excel. Click these arrows and make sure you uncheck the "use original column name as prefix" option box and ensure that the EXPAND option is selected. Then click okay.
7 At this point it looks alot like your report. Go to the HOME tab -> TRANSFORM ribbon -> Use first row as headers.
8.Select only the columns that are NOT THE 24 hr STYLE TIME LABELS of your report and then right click -> Unpivot other columns
9 At this point you can start removing some of the columns you dont want by right click and remove. Also double click and rename the columns as you wish. You can right click the top of the column and change types to what you want.
Dont worry about the 24HR style time zones not looking correct as this will be fixed later, this column should be changed to decimal type and not time zone type.
select a column that has the date information you need and right click -> Duplicate column -> change type to date.
11.At the top left part of the screen there is a CLOSE AND LOAD drop down where you will load to a new worksheet.
That will produce a green table. Select the table and press ALT+D+P to produce a pivot table linked to the green table you produced from the query.
You may need to close the Queries and Connections box that opened in order to see the pivot table options that will appear on you right.
Drag the 24hr style column to the columns area.
Drag the People to the Rows area and after Drag the Column you made in step 10 to the Rows area.
Drag the conditional format column to the Values area.
Your pivot table wont look exactly like what you want. while pivot table is selected go to DESIGN tab -> REPORT LAYOUT -> Tabular and also SUBTOTALS -> DO NOT SHOW SUBTOTALS while in the same tab.
13 Highlight all of the 24hr style time labels and format them and after highlight the inside of the pivot table where all the 1 and 0 will be and apply the conditional formatting you applied previously. Dont forget you changed the formula originally so your if statement does not end with "" but instead with 0.
If you would like i think it is easier to switch around the ROWS and COLUMNS area of the pivot table fields so that the report is easier to read. I have chosen to do so in the pictures. If you want to keep the report the way you are used to you can follow previous instructions.
I put the above comment down here as a complete answer.
I call those cells after "Finish date" column as "Chart cells". To extract a unique list of names, please refers to: here
If each name, you can use the followings formula and format for cells value >0 to show the bars.
=SUMIF([name range], "[each name]", [for each column of the chart cells])
If you further needs to filter by dates, you need to use sumifs() instead:
=SUMIFS([each column of chart cells], [name range], [unique name obtained from above], [Finish date range],"<=" & DATEVALUE("[target date]")+1,[start date range],"<=" & DATEVALUE("[target date]"))
This is the Excel formula solution, which is good if your table is not huge.

How to properly index match using dates between two different tabs

I am trying to automate a report, but I am running into some errors when trying to use index match to report data for matching dates between to excel sheets.
In the pictures below, I want the table to be populated when data is pulled in another tab and the dates in the table match the ones in the tab where the data is pulled. For instance, where it says 'Mar-18', i want to report the data from the 'ACT STND PRODUCTION' line in the SPI Performance tab where it says '03.2018'.
Graph tab
SPI Performance tab
The first tab is called Graph and the second is called SPI Performance. Right now , I have =INDEX('SPI Performance'!C6:C14,MATCH('SPI Performance'!$B$10,'SPI Performance'!$B$6:$B$14,0),MATCH(Graph!D26,'SPI Performance'!K5,0)) for the Mar-18 box in the table, but i am getting an error.
Thank you for any feedback you may have!
Please try this formula to see if the cell will populate correctly:
=INDEX('SPI Performance'!$C$10:$K$10, MATCH('Graph'!D26,'SPI Performance'!$C$5:$K$5,0))
If you enter that formula in cell D27 on the "Graph" Sheet then drag it to the right through column M the answer should populate based on the ACT STND PRODUCTION line in the 'SPI Performance' Sheet.
You can alter the ranges $C$10:$K$10 and $C$5:$K$5 as needed depending on how large your range needs to be.

(Excel) Neither Offset nor Index/Match prevented a table's referenced cell from moving

I have a report that consists of 3 different input, and 3 corresponding output tabs for 3 different sources of information. Each source needed a Macro to change the formatting of the data. One of these sources needs data for individual days, so as it formats the data into a table, it is copying and inserting the cells on top of the previous day's data. Once 5 days of data has been converted and stacked in the output tab, a final tab has essentially all the formula's, dubbed the "Conversion" tab. In this tab there are 3 tables for each source of data (the output tabs) and a fourth that takes the data from these 3 tables, and combines them into what a final macro copies and pastes the values from into a new sheet.
The problem lies in that sheet that stacks the data by inserting the new rows. I've done everything from Index and match, Offset and match, simple offset, Vlookup (obviously, that's the go-to at first) and even Defined the name of new formula's, but the cell that the Conversion tab's table references keeps moving down as new data comes in. I need to reference Array 'CampPerf Output'!B116:B135
no matter what. What formula can I use or backdoor trick can I use so that my lookup looks at the exact same array every time?
The macro that converts the data has to be a repeatable action so I can assign it to a button (This report must be made as simple as possible, as Non-Excel Users need to be capable of "paste data, click button, click other button, ta-da!")
Thanks for any help!
Use this as your range reference:
INDEX('CampPerf Output'!$1:$1048576,116,2):INDEX('CampPerf Output'!$1:$1048576,135,2)
This will always return the range array in 'CampPerf Output'!B116:B135 no matter how many rows or columns are added or removed.

Filter column for substring and return max of adjacent cells -- Excel 2013 (no macros)

I would like to obtain the max call time that was on each day, the average of all the calls that day, and any calls that exceeded 20 seconds.
Due to the security policies at work I am limited to the formulas provided by excel, I can't use macros or VB (otherwise I would just write something suitable). I don't have much experience with excel, so I apologize if this is a simple one. I have tried to find ways to search and return a subarray that I could easily manipulate, but it seems the only way to do that is with macros. Currently I think I can use VLOOKUP, but I don't really understand enough about it know if I can use this with another function.
Essentially, if there is a formula or a combination of formulas that I can use that will allow me to collect all data from column B that shares the same values in column A, I could nest that in the formulas I need to calculate the data.
Any help is appreciated!
This can be done with a pivot table in just a few clicks.
First, turn the source data into an Excel Table object, by selecting one cell in the table and then using Insert > Table or Ctrl-T. Add a helper column for the calls over 20 seconds. Let the column be "long calls" and the formula
=IF([#Duration]>TIME(0,0,20),1,0)
Then, with a cell of the Excel Table selected, click Insert > Pivot Table. (The pivot table is now linked to the Excel Table object and when more data is added you can refresh the pivot table without having to change the definition of the source data.)
Drag the Day field into the rows area and the Duration field into the Values area. Right-click any of the value results in the pivot table, and in the Value Field Settings dialog select Max. Then click on Number Format button and set the custom number format of hh:mm:ss. Confirm all dialogs.
If you want to format the date, right click any of the visible dates in the Pivot table, select Field Settings, click Number Format and then set the custom format ddd.
Drag the duration field into the values area again and set its calculation method to Average.
Drag the "long calls" field into the values area.
Hide the Grand Totals via the Pivot Table tools Design ribbon command.
Now you can add more data to the table in columns A to B, right click the pivot table and select refresh.

Excel table not expanding when new data is added

I have an Excel spreadsheet which contains four data tables on the same tab. The final 3 columns in each contain formulae.
I then have a vba code which performs an sql look up within an SQL Server table and returns a set number of columns to update each of the four tables.
For three of these tables, the data is pasted in and the table automatically expands and the formulae is copied to the end of the table.
However, for the first table, the data is pasted in but the table does not expand and hence, the formulae does not get added to the rows outside of the table.
I have searched high and low for a fix but no joy. I have searched the data extraction VBA code with no luck (the code is an exact match) and no joy in the table properties. I have also checked the Options menu for Auto Format As You Type settings but all seems fine.
Does anyone have any ideas for me?
Thanks,
David.
Hi All again,
Would love to know if anyone has an answer for this but, in the mean time I have fudged the code to automatically adjust the size of the table based on the row number for the last cell of data.
Thanks,
David.
I ran into the same issue and it was driving me nuts. Found out that in a few columns I had dragged formulas down pretty far (they were IF statements to return nothing if the first column was empty) so I didn't see them.
So remove any formulas that are 'under' the last row of the table. Should clear up the issue.
The most common cause is due to differing number of, or mis-aligned columns (vertically stacked tables) or differing number of, or mis-aligned rows (horizontally stacked tables).
For simplicity, let us use vertically stacked tables to illustrate what is happening. Consider an upper table with 2 columns and a lower table with 3. If we try to insert a row to the upper table, XL attempts to push all cells beneath the table down, but ONLY the cells directly beneath the table. So in this case cells below the 2 columns will be pushed down. XL quickly realizes that if it pushes just 2 columns down, the third column in the lower table won't be pushed down resulting in skewing the lower table. XL makes no attempt to figure out how to move the lower tables. It just refuses to even try.
The same holds true for adding columns to tables on the left for which there are tables directly to the right. If adding columns to a table would result in skewing rows of a table to the right, XL refuses to help.
To keep this from being a problem we can do a few things:
Keep the largest tables on top and to the left and align all table first columns and first rows.
If only rows are added to tables, don't stack them vertically
And if only columns are added to tables, don't stack them horizontally.
Herewith is an example of enforcing expansion of a table after data was copied over to the bottom of the table. This is done by resizing the table. Originally the table wasn't auto-resized as it has additional calculation columns.
The first line of the code finds the last row of data and the second line states the range to which the table needs to be resized. The third line resizes the table to the new range.
Replace sXXX and tXXX with your sheet name and table name.
Sub ResizeTableXXX()
myLastrowOfData = sXXX.Range("A1000000").End(xlUp).Row
myNewRangeSize = "$A$5:$P$" & myLastrowOfData
sXXX.ListObjects("tXXX").Resize Range(myNewRangeSize)
End Sub
HIH

Resources