Analyse Data like a Super Hero
In mid May, Anup47 asked a question in the Chandoo.org forums about the use of a VBA macro to run a number of iterations of a variable against two sets of X values, you can see the post here. It turns out that the number of iterations was 500 columns of data with each column having 27 values.
On examination of the problem, it was going to be a straight forward matter of setting up a statistical function Linest and then using the Data Table command to run each set of data through the function.
The Linest will take the input data and return the statistics that Anup wanted.
The Data Table function will feed in the source data and tabulate the Input and Output data.
This Post follows through a worked example which you can follow along, download the Sample file to suit Sample File 97/2003 or Sample File 2007/10 version. The Sample File contains a worked example of the completed model as well as a Practice Page of the original data. Download the Excel 95/2003 or 2007/10 version above.
Please note that the sample file only contains 14 sets of data as opposed to the 500 Anup47 wanted to process.
Setup
There are a few things that needed setting up before the work starts.
 Headers
 Linest Area
 Link Area
 Data Table Area
Once these areas are setup we simply use the Excel Data Table function.
Once the Data Table function has run, the results can be processed or analysed as required.
Headers
The original data was just that, a tabulation of raw data. The two X sets of Data were in Columns 1 & 2. Each Column from D onwards has a set of Y data that was to be processed.
The first thing that was required was some Headers for the Input Data.
This isn’t strictly required but it is good practice and makes it easier to tabulate and analyse results later.
Insert a Row above the first line
Put X1, X2 in A1, B1 and Y1 in D1 and then drag the lower right Black Handle across top to the right and Excel will autofill the remaining cells.
Linest Area
To get the statistics which Anup wanted we will use the Excel Linest function.
Linest is a Statistical Function that takes a set of data and compares it, in this case to two sets of X Values and produces a set of statistical measure relevant to the correlation between the data sets.
This post isn’t going to explain the intricacies of Linest and I refer you to the Links section at the end where you can read more about the Linest function at your leisure.
For our purposes we need to know that Linest is an Array Formula and requires a 5 Row x 5 Column area to be entered into. For now we will just Array Enter the function =Linest($D$2:$D$28,A2:B28,True, True) into B32:F36.
To do that select the range B32:F36, Press F2 and type/paste the equation in, then Array Enter with Ctrl Shift Enter.
Link Area
To Link the Linest equation to a Data Table we need a link cell, which we will put just above the Linest area.
For now just enter a 1 in it.
We can now go back to the Linest area and link the Linest equation to our link area using the equation, =LINEST(OFFSET($C$2:$C$28,,$B$30),A2:B28,TRUE, TRUE)
To do that select the range B32:F36, Press F2 and type/paste the equation in, then Array Enter with Ctrl Shift Enter.
What this does is allow the Linest formula to access different columns Y1 to Y500 depending on the value of the Link cell B30 which is now 1.
Data Table Area
To setup a Data Table area we need a column of Inputs which will be the Run Numbers and the Row Inputs will be links to the Input and Output Cells.
In a range J33:J46 put the values 1 to 14. These will be the Run Numbers. ie Run No 1, Run No 2 etc (Green in the example below).
Across the top of the Data Table area we can put a number of links and associated labels (Yellow and Blue)
In this case there are 4 Output links =B31, =C31, =B34 and =B33 and their associated labels above them, as well as 2 Input equations and there Labels. The Input equations are simple Offset function that retrieves a value from Rows 1 or 2 based on the value of the Link Cell B30.
These are technically not required but make data analysis and identification of individual results later on a lot simpler.
Run Data Table
We can now run the data Table by selecting the Data Table area: J32:P46
Noting that we will be using a Column Input cell and that it will link to $B$30, the Link cell for the Linest command.
What this does is takes the first value from the Column J32:J46 and puts it into B30, then the Linest command will be calculated and the results put into the Data Table area along with the Inputs.
This is repeated for each cell in J32:J46 automatically.
The final Data Table is now populated as below:
You can see by extending the Data Table input column from 14 to 500 that the full 500 columns of Input Data could easily be processed.
Results
You now have a setoff data that can be analyzed using normal statistics, Min, Max, Std Deviation etc, or can be fed into a Pivot Table/Chart for analysis etc.
References
Linest References
http://chandoo.org/wp/2011/01/26/trendlinesandforecastinginexcelpart2/
http://newtonexcelbach.wordpress.com/2011/01/19/usinglinestfornonlinearcurvefitting/
Data Table References
http://chandoo.org/wp/2010/05/06/datatablesmontecarlosimulationsinexcelacomprehensiveguide/
How can the Data Table command help you become a data processing super hero?
How can the Data Table command help you become a data processing super hero?
Let us know in the comments below:
Hello Awesome...
My name is Chandoo. Thanks for dropping by. My mission is to make you awesome in Excel & your work. I live in Wellington, New Zealand. When I am not F9ing my formulas, I cycle, cook or play lego with my kids. Know more about me.
I hope you enjoyed this article. Visit Excel for Beginner or Advanced Excel pages to learn more or join my online video class to master Excel.
Thank you and see you around.
Related articles:

Leave a Reply
« Register for our Excel & Financial Modeling Bootcamp in Singapore [Details inside]  We Want Your Ideas » 
8 Responses to “Analyse Data like a Super Hero”
Great  Learned Something New Today.
[...] http://chandoo.org/wp/2011/06/20/analysedatalikeasuperhero/ [...]
Hello
I have a historical data of particular company like 5 yrs daily closing price.
I have to calculate GARCH and volatility that company could u pls help me
cheers
rvn
@Vivek
I'm unfamiliar with GARCH
But, Have a look at http://www.youtube.com/watch?v=KJbR0nRinD4
Hi,
I have data for two analyst performing same taks in two diff columns. How do i get to know who is the better analyst.
Regards,
Renato.
I want to learn to use multiple sheets (one for input) and second for modeling. When I am using data table, I got an error "Input cell is invalid" when I try to use a different sheet. i found the following on microsoft website. I am trying to link the cell and try again, but linking the cell is not clear to me beside =Sheet1!C3. This method does not work.
https://support.microsoft.com/enus/kb/95811
Here is an example
Sale rep salary is in column 1
Net Profit is in column 2
Row 1, column 2 net profit entry is a reference from other sheet.
Using =Sheet1!C3
$38.66 is =Sheet1!G13
Sales Salary Net profit
$38.33 60000 (<=== This is used =Sheet1!C3)
40000 38.33295155
45000 38.33295155
50000 38.33295155
55000 38.33295155
60000 38.33295155
65000 38.33295155
70000 38.33295155
75000 38.33295155
80000 38.33295155
As you can see the values generated by the table is identical. I am not sure what is going wrong and how to use this workaround?
Thanks,
MP
In above example Row1, column 1 is empty (assumption, but alignment issue when posting).
I am referring to $38.33 and 60,000 row.
It's empty cell in column1, $38.33 in column2, and $60,000 (outside the table, column 3).
In whatif analysis, column selection is $60,000.
Regards,
MP
Hi Chandoo/Hui
The example above has columns as a variable. I'm trying something a little different.
I'm working with a table trying to figure out a way to use linest() only with a select number of rows. The selection is based on a product. A bit like sumif(). I have plus 100.000 rows of data and a number of products.
Is there a way/formula to select/filter the datainput to Linest based on the product without using VBA? (I guess I could use VBA to filter and copy the relevant data to a new sheet but I'm trying to avoid VBA in this context).
Input are most welcome
Christian