Multiple series into one line in line graph in Excel? - excel

I'm trying to make a line graph in Excel that combines multiple series into ONE line. All I've been able to create so far is one graph with multiple lines on the same y axis. Is it possible to combine multiple data points from multiple series together in chronological order?
For context: I'm trying to make a graph that shows monthly temperatures between 1880-2017. January, February and so on, are each a separate series. I can make a bar graph that shows each year with each month chronologically but is there a way to convert this into a line graph without it producing multiple lines for each month, but instead one line that combines all the month data points together nicely?
Thanks!

If there no gaps in the data you described,
and you have a table
of (2017-1880+1)=138 rows by 12 columns.
Here it is one way to make a one-line graph of the data
(some random imaginary data used in the example).
Unfortunately, standard Excel data functions can handle only
dates not older than January 1, 1900,
see for example, http://www.exceluser.com/formulas/earlydates.htm.
But you are lucky as all you need is just a year and a month numbers.
In this case the dates along the x-axis
can be presented with numbers, which integer part is the year,
and fractional part is a fraction of the year that represents a month.
Assuming that the table is in Sheet1!A2:M139,
select Sheet2 , type in a formula
=1880+FLOOR((ROW()-2)/12,1)+MOD(ROW()-2,12)/12
in the cell A2, and copy it down to A1657 by any means you like.
For example, select A2, press Ctrl+C,
click in the Name box input field,
type A2:A1657 range in it and press
Ctrl+V.
That's it, this will create all the
x-axis date values for the one-line graph.
Next step is to fill the range B2:B1657
consequently with monthly data from the Sheet1.
Select cell B2 and type in a formula
=TRANSPOSE(INDIRECT(ADDRESS(2+LEFT(A2,4)-1880,2,,,"Sheet1")&":"&ADDRESS(2+LEFT(A2,4)-1880,13)))
select range B2:B13,
click at the end of the formula and press
Ctrl+Shift+Enter.
The range B2:B13 is now filled with the T data from Jan to Dec of 1880,
and it is still selected.
Press Ctrl+C to copy this range,
then select B14:B1657 and press Ctrl+V.
That's it, all the readings from the table
will be lined in the range B2:B1657.
Edit
There is even simpler solution for the second part:
fill the range B2:B1657 with formula
=INDEX(Sheet1!$B$2:$M$139,FLOOR((ROW()-2)/12,1)+1,MOD(ROW()-2,12)+1)
It just converts a linear x coordinate of the current point,
based on the subsequent row number ((ROW()-2)) into corresponding row, column pair
in the table and extracts the table value with INDEX() function.

Related

How can I get my Excel spill range to be grouped by a specific column for a chart?

I need to produce a chart in Excel to show a quantity of items for a number of categories, grouped by the month they were received. At the moment, every occurrence of the Month shows up in my clustered column chart. I can manually do a table and remove all except the first occurrence of each month, but I need it to be done dynamically as the date range can be changed (between 1 and 12 months). I have a full list of data for 12 months, showing Types and their Quantity received. I've filtered the list to just show the types and quantities received between the date range selected (picture 1).
The three images below show the spilled data, the current chart, and how I would like the chart to look. If it cannot be achieved directly using a spill range, then could anyone suggest another approach to have my data dynamically displayed in a chart, grouped by month?
Not a perfect answer but here's a start:
You could paste:
=IF(COUNTIF(F$5:F5,F5)=1, F5,"")
in J5, and drag this down a sufficient way to cover the expected length of the dynamic array.
Then paste:
=CHOOSECOLS(F5#,2,3)
in K5, and use these three columns for your graph data.
I can't think of a way to make the "J" column dynamic at the moment.
EDIT:
Pasting:
=XLOOKUP(ROW(F5#), XMATCH(UNIQUE(CHOOSECOLS(F5#,1)),CHOOSECOLS(F5#,1))+4, UNIQUE(CHOOSECOLS(F5#,1)),"")
in J5 should work dynamically too.

Updated Weekly Comparison between two values

I am trying to make an excel for keeping track of body weight.
On each SUNDAY, the new weight will be inputted by the user, this will go on for an infinite amount months. I want to be able to calculate the difference between last Sunday's input and the current Sunday's input when a new weight is inputted, then display the difference in a cell.
The problem is, I can do this for the first two inputs, but I want it so once you have 4 inputs, it will no longer use the 1st two weights for the calculation, but the 3rd and 4th, and same with 8 inputs, where it would use the 7th and 8th input for the calculation instead of 1st-6th and so on.
I have tried conditional formatting and if's, although it does not get the "use newest 2" effect I want. What could I use to do this?
Make sure you have a 'spare' column to the left of your weights. Let's take column A as the spare and then record your weights in column B. Allowing for column headings and generally laying things out nicely, let's say your first weight data is in cell B4, then the following week's data is in B5 and so on. In cell A4 enter the formula:
=A3+IF(B6=0,1,0)
Now copy this formula down for as many rows as you need in column A. Your formula to get the difference between the newest two weights is:
=VLOOKUP(2,A:B,2,FALSE)-VLOOKUP(1,A:B,2,FALSE)
[EDIT - allowing for 'calendar' view]
For you calendar view you are going to need a spare row above your weight data. You could hide this row if you wanted. Allowing for blank cells between your inputs I would use a slightly different technique. In this spare row (e.g. cell D2) put the formula:
=C2+IF(D3=0,0,1)
Copy this formula all the way to the right. The formula for your newest difference calculation now becomes:
=HLOOKUP(MAX(2:2),2:3,2,FALSE)-HLOOKUP(MAX(2:2)-1,2:3,2,FALSE)
If the entries will consistently be on a Sunday and on a weekly basis and you were happy to include the date in column A and your weight in column B then keep a rolling formula in column C:
In row 5: =b5-b4
In row 6: =b6-b5
This formula in column C can be dragged down using the small box in the bottom right of the cell and will automatically change the row number for you.

For dates with missing data, take average of values from closest dates

I have sporadically collected data for stream nitrogen levels. For dates where nitrogen levels are not available, I'm hoping I can use an Excel formula that will estimate the value by calculating the average of nitrogen levels from the two closest dates.Note that nitrogen is not correlated with flow (or other water quality parameters) and there is no trend so I can't use a regression equation to estimate values.
Below is an example of what the table looks like for columns A, B, and C, and rows 1 (header) to 7. Column B contains the real data (note that I inserted 'no value' for illustrative purposes). Column C is what I would like to have calculated. Because I have thousands of rows of data, manually entering each of these formulas is not an option.
Date_______Actual Value______Desired Calculation
1/1/2012_______0.15__________=B2
1/2/2012_____[no value]_______=AVERAGE(B2,B5)
1/3/2012_____[no value]_______=AVERAGE(B2,B5)
1/4/2012_______0.17__________=B5
1/5/2012_____[no value]_______=AVERAGE(B5,B7)
1/6/2012_______0.23__________=B7
=IF(B1<>"",B1,VLOOKUP(MAX($A$1:$A$4),$A$1:$B$4,2,0))
Misread the question the first time.
Test to see if B1 is equal to "" or not. If it is empty then perform the VLOOKUP searching for the max value of column A (most recent date), and then use the value for the adjacent column (2).
This will not cover the case where the most recent Date has no value in column B. I will return "" in that case.
TREND Option
Based on your comments and the use of some helper cells you could do the following. Make a small table off to the right somewhere of just your known dates and your known values from B. We can populate this table using the following formulas. Let arbitrarily put this table in columns F and G.
in F2 use:
=IFERROR(INDEX($A$2:$A$1564,AGGREGATE(15,6,(ROW($B$2:$B$1564)-ROW($A$2)+1)/($B$2:$B$1564<>""),ROWS(B$2:B2))),"")
This will pull the dates in order that they appear with values in B that are not "". Then in G2 put the following formula in which will pull the associated value from B
=IFERROR(INDEX($B$2:$B$1564,AGGREGATE(15,6,(ROW($B$2:$B$1564)-ROW($B$2)+1)/($B$2:$B$1564<>""),ROWS(B$2:B2))),"")
Both those formulas are currently set up to work with a header row and data starting in row 2.
once we have the helper table set up, you can set up a TREND function, which is a line of best fit through all your known points. You can pick the point on this line for dates with no value in B. In C2 you would add:
=IF(B2="",TREND($G$2:$G$3,$F$2:$F$3,A2),B2)
you would copy this formula down. It checks to see if B is blank. If it is then it pulls a value for B from the trend line. If it is not blank, then it will use the value in B.
AVERAGE Option
Again using the helper table in the same spot. This one gets a little uglier. In C2 place the following and copy down
=IF(B2<>"",B2,IF($A2<$F$2,$G$2,IF($A2>$F$3,$G$3,(INDEX($G$2:$G$3,IFERROR(MATCH($A2,$F$2:$F$3,1),1))+INDEX($G$2:$G$3,IFERROR(MATCH($A2,$F$2:$F$3,1)+1,2)))/2)))
The first thing it does is check for a blank value in B. If there is no blank then it uses the value in B2. If there is no value in B2 it then proceeds to check the date of the blank against the first date in your helper table. If it is less than that first value, it uses the first value of B since there is nothing to average it with. I then proceeds to do the same to see if the date exceeds the last value in the table. (this is currently hard coded). If it exceeds the last date in the table it uses the last value for B. the last option for the date is for it to be in the table. It take the average between the date prior to the date and question and the next date with a value.
Optional version where you dont have to hard code the last values of helper table, but you still need to hard code the range of the helper table to meet your needs.
=IF(B3<>"",B3,IF($A3<$F$2,$G$2,IF($A3>MAX($F$2:$F$3),VLOOKUP(MAX($F$2:$F$3),$F$2:$G$3,2,0),(INDEX($G$2:$G$3,IFERROR(MATCH($A3,$F$2:$F$3,1),1))+INDEX($G$2:$G$3,IFERROR(MATCH($A3,$F$2:$F$3,1)+1,2)))/2)))
TREND Between only two points
So I adjusted the formula a bit on this one. Its kind of a mix of the trend and previous options listed above. I also made it automatically selecting the end values of your table, so now you just have to copy your table down as far as you need. Its also works on the premise that only your data value in B are present, no numbers below your last row.
=IF($A2<$F$2,$G$2,IF($A2>=MAX(OFFSET($F$2,0,0,COUNT(B:B),1)),VLOOKUP(MAX(OFFSET($F$2,0,0,COUNT(B:B),1)),OFFSET($F$2,0,0,COUNT(B:B),2),2,0),TREND(OFFSET($F$2,IFERROR(MATCH($A2,OFFSET($F$2,0,0,COUNT(B:B),1),1),0)-1,1,2,1),OFFSET($F$2,IFERROR(MATCH($A2,OFFSET($F$2,0,0,COUNT(B:B),1),1)-1,0),0,2,1),$A2)))
So basically TREND function is a line of best fit through known points. if your know points do not all sit in a straight line it figures out what straight line passes near them minimizing the distance they are from the line. If we limit the points it using to make its line to only 2 points, then the line has to pass through those two points. Remember, the helper table is a list of all known points.
So basically what the formula doing is checking to see if the date is less than or equal to the first known point on the helper table. If it is, use the value from the first known point in the table. If its not, check to see if the date is greater than the last date in the table, if it is lookup the last known date in the table and return the corresponding table. If neither of these cases is true then the date must be in the table. That means we can get two points from the table and their corresponding values to use in the trend function. We feed the TREND function a an array of 2 known X and 2 Know Y values, and then supply it with an X value we are interested in. In this case X would be the dates, and Y would be the values in the second column.
Revised Helper table
In F2 use this formula:
=IFERROR(INDEX(OFFSET($A$2,0,0,COUNT(A:A),1),AGGREGATE(15,6,(ROW(OFFSET($A$2,0,1,COUNT(A:A),1))-ROW($A$2)+1)/(OFFSET($A$2,0,1,COUNT(A:A),1)<>""),ROWS(B$2:B2))),"")
and G2 use this formula:
=IF(F2="","",INDEX(OFFSET($A$2,0,1,COUNT(A:A),1),MATCH(F2,OFFSET($A$2,0,0,COUNT(A:A),1),0)))
and if you want to verify how far down you want to copy your helper table, you can put this in lets say I3:
=COUNT(B:B)+1
Now these update that are using the count(A:A) or B:B require that no other numbers be above or below your data in the A or B column.
UPDATED Average
I also tweaked the average formula to give this option as well.
=IF($B2<>"",$B2,IF($A2<=$F$2,$G$2,IF($A2>=MAX(OFFSET($F$2,0,0,COUNT($B:$B),1)),VLOOKUP(MAX(OFFSET($F$2,0,0,COUNT($B:$B),1)),OFFSET($F$2,0,0,COUNT($B:$B),2),2,0),AVERAGE(OFFSET($F$2,IFERROR(MATCH($A2,OFFSET($F$2,0,0,COUNT($B:$B),1),1),0)-1,1,2,1)))))
Example results (note rows 14-69 have been hidden so you can see what is happening around row 75.

Countif with dynamic headers

Good afternoon! I'm trying to get a Countifs or Index Match statement to count the number of times a value occurs in another table. The example:
On my report sheet, Column A contains 10 different statuses, such as Green, Yellow, Red etc.; Row 1 contains six dates, such as 1/31/2015, 2/28/2015, etc. These dates are calculations. The last date references my date worksheet and the five other use EOMONTH to get the month end for the five prior months.
On my data table, I have 7 descriptive columns (such as Type, Make, Model, etc) and then we begin date columns: 1/31/2010 all the way to 7/31/2015. I add a new column each month (I know, I don't like it either, but unfortunately we don't have a time series database).
What I need to do is have a Countifs or Index Match that pulls the date from my report tab, goes and finds it in the header row of my tblTrends, and then counts all those statuses that are Green, and if it's a SUV (for example).
Thoughts?
Thx!!
G
At it's most basic, you'd want something akin to:
=COUNTIFS(TypeRange,"SUV",FirstMonth,Status)
So let's say your data table starts in column L, and the first date column is O:
=COUNTIFS($L$1:$L$100,"SUV",O$1:O$100,A$2)
As you drag this formula across the different dates, it will move the date reference over one to the next month.
If you need it to dynamically determine the date column, I'd recommend OFFSET, which dynamically select a range. However, note that OFFSET is a "volatile" formula, which means it re-calculates anytime a change is made anywhere in the file, which can lead to pretty slow load times if not used sparingly.
=COUNTIFS($L$2:$L$100,"SUV",OFFSET($N$2:$N$100,,MATCH(B$1,$O$1:$Z$1,0)),$A2)
The OFFSET starts on column N, because that's the first column before the columns we want (the date columns). The MATCH tells it how many columns to OFFSET from here.
If you're going to use this over a large amount of data, then you could avoid using the OFFSET formula by creating a dynamic table. This table would only contain data for the six months you're interested in, by utilizing INDEX/MATCH, and you could run your COUNTIFS off this table, instead, using the original, basic method I first described. I can go into detail if you're unsure what I mean.

Excel Line Graph - Putting 2 rdifferent Variables on X Axis from table

I'm having trouble putting data on 2 different types of data on my x-axis from the data in my table. How can I get the month and year data from my table to a line graph like this?
Like in the graph shown, I want all to group the x-axis by year range (2001-2002, 2002-2003, etc). And then within each year range, I want the values for each month to show for that year from August to May. And repeat this again for each year interval.
What should I select on select data source to make it look like the graph shown?
In Excel, you can arrange your data this way (I've only included 3 years):
Every cell that seems blank is really blank, that is, it doesn't contain a formula or a space or anything that doesn't appear. The "XXX" in the second cell of the second column is temporary. Create your line chart with this data, then delete the "XXX" and format the chart.
Recommend combining the month and year dimensions into a single month-year column and making the values line up in a single column. Then put month-year on the x axis and values on the y axis.

Resources