SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
An Introduction to Array Functions, Offset Function, and Defined Formulas
         With Applications to Pivot Table and Chart Maintenance


                        Barry Posterro – July 2009
Array Functions


Most functions we use take in multiple values and return one answer:

         Ex:    = SUM (A1:A5)
                = AVERAGE(A1:A5)
                = A1 * A5
                = A1

All return one value only and put that result in the cell where the function was written.


An array function takes in a range of values (like A1:A5) and returns a range of values.

Steps:
         1) Select the entire range where you want the results to appear (results range)
         2) Enter your formula
         3) Finalize your formula by pressing CTRL-SHIFT-ENTER


Ex: Simply reference the cells A1:A5 in cells A13:A17




                                                                                            2
The results are:




Things to notice:

       1) The function has brackets around it.

               These are added by Excel and tell us that we entered an array function.

       2) The function is the same in each of the cells A13:A17.

               This highlights the point that we only entered one formula, not five
       formulas. The only formula actually being calculated is the one in cell A13.
       Cells A14:A17 are just used for holding results, not calculating results. They
       contain the formula only as an auditing tool to tell us what function created these
       values.




                                                                                             3
Array Function Security

       One of the nice things about array functions is that they add a level of security
that we do not otherwise have if we’d entered in separate formulas.

       Attempt to delete cell A16. You should get the following error:




You cannot break up an array formula after you have entered it. Excel enforces the
integrity of the formula. This error is not limited to a delete attempt. Trying to edit any
of the 5 cells will result in the same error.




                                                                                              4
Editing an Array Function

       1)   Re-highlight the entire results range
       2)   Press F2 to enter the function edit mode
       3)   Edit formula
       4)   CTRL-SHIFT-ENTER

Ex: Change the formula we already entered to reference column B1:B5




Notice that once you’ve edited the formula (but before CTRL-SHIFT-ENTER), the new
domain will be outlined even while the results in A14:A17 are unchanged. Pressing
CTRL-SHIFT-ENTER will cause the execution and those cells to update.


Deleting an Array Function

       Select the entire results range (A13:A17) and press delete. To delete an array
function, you must delete all of the cells it uses.




                                                                                        5
Some Excel Array Functions – not so useful to us

         Excel has some array functions of its own. A lot of these are associated with
statistics and data fitting.

       LINEST - fits data to a line y = mx+b. Given y’s and x’s it returns m and b.

Ex:




The results are 1 and 10, which make sense, since the columns differ by 10. It’s a good
idea to read the help files associated with any new array function you are using from
Excel’s library. This function returns its results in row form. If you had highlighted two
stacked cells like C13 and C14, you would have gotten the result 1 twice.

       Like LINEST, there is also LOGEST, which estimates the fit        y = b*m^x

        TREND – uses the linear estimate of LINEST to produce what the fitted values of
the data would be.




                                                                                         6
Some Excel Array Functions – useful to us

Often we find ourselves in a situation where we receive data in one orientation (column)
but need it in the other orientation (row) for what we need to do. The array function
TRANSPOSE handles this:

Ex: Take Column B and make it a row.




We can also use this to transpose the entire table. This is our first use of a two
dimensional array.

Ex:




                                                                                           7
OFFSET

This is a very useful array function that the rest of this lecture will rely upon. It returns
an array of values in the shape that the user specifies.

It takes five inputs.

OFFSET ( cell_anchor , rows_down, columns_right, height, width)

The last two inputs are optional. They default to 1 if omitted.


Ex:




This example returns an array formed by:

        1)   relative to A1
        2)   move down 2 rows
        3)   move over 1 column - now we’re in cell B3
        4)   return a 4 row, 5 column array with cell B3 as the corner




                                                                                                8
NOTES:

If you want the cell_anchor to be the corner of your results, set the rows_down to zero
and the columns_right to zero.


Ex:




You can also enter negative numbers for your rows_down or columns_right parameters.

Ex:




                                                                                          9
A height of 1 implies a row. A width of 1 implies a column.

Ex:




                                                              10
As mentioned earlier. Leaving off the last two parameters results in a single cell as those
parameters each default to 1.




Notice that if we’re only returning one cell, we do not need to use CTRL-SHIFT-ENTER
and there are no brackets around the formula in the formula bar.



Calculations

So far, we’ve just been returning data, but we can also use OFFSET as the input to any
function that takes in an array. For example, SUM or AVERAGE.

Ex:




                                                                                         11
This method allows us to make formulas in which the number of points to average can
become one of the inputs to the formula. Let’s look at this with rolling averages.




For each period, we take the average of the last number of months given in column A.




                                                                                       12
OFFSET with TRANSPOSE

Keep in mind that the display area must be the same shape as the array created by the
offset function or you may get unexpected results. The following is what occurs if we try
to put a row created by offset into a column:




If a column is really what you want here, you need to invoke the transpose function.




                                                                                       13
DEFINED NAMES

While we employ using defined names to refer to cells in a workspace, the defined names
capability of Excel also extends to formulas and constants (constants being a very simple
formula.)

Ex: Define the word “million” to be 1,000,000.




                                                                                      14
Now, typing “=million” in any cell will return that value.




And, we can use it in any formula like a variable.




                                                             15
Likewise, we can define and name a formula.

This formula sums up all of column B:




Putting this name in any cell will return the sum of column B.




                                                                 16
COUNTA

        -   simple function that returns how many values are present in a rang of cells

Ex: First, let’s triple the size of the data.




This function is the last key to the payoff of the earlier work we did.




                                                                                          17
Self-Updating Pivot Table

       The argument of a pivot table’s range property is usually a set area of a
spreadsheet. For example:




As we know, if the dimensions of this area change, we need to reset the range argument
of the pivot table. That is, if more rows or columns are added, we need to tell that to the
pivot table.

Using OFFSET, COUNTA and a defined name, we will make the argument of the pivot
table’s domain a defined name that will never need to be updated.




                                                                                          18
Step 1. Create an array that uses variable arguments for its size.




In an easier to see view:

=OFFSET(Sheet1!$A$1,0,0,counta(Sheet1!$A:$A),counta(Sheet1!$1:$1))




                                                                     19
Pressing ADD, and then clicking into the formula bar, Excel will highlight the area that
you are referencing with this formula.




                                                                                           20
Step 2. Assign the name PT_data (or whatever you called this) to the range argument of
the pivot table.




Step 3. Click Finish and you are done.




                                                                                     21
Now, going forward, as long as the data you want begins in the same corner as the data
you are referencing with your defined name, PT_data, you never need to go through the
Pivot Table options again to reset the range as more rows or columns are added.

Let’s see that. Add another column of random data call “Garbage” and fill it in. Also,
add another row called “Test.”




                                                                                         22
Now, simply refresh your pivot table.




The new field, Garbage, shows up now, and if you drop Dates into the row field, you’ll
see Test now shows up as well.




                                                                                         23
Notes:
       Beware of rogue data corrupting your defined name PT_data. Because the
COUNTA is counting all values in the row and column, having stray values in those rows
or columns will corrupt your dimensions. Also, make sure that you pick a column for
COUNTA that will never be empty or your PT_data will not have as many rows as you
need. The correct column to pick is not always the far left column.
       Also, while we call these “self-updating,” that only refers to the range. If data
within your table changes, you still need to refresh your pivot table as you normally
would.




                                                                                     24
Self-Updating and/or Interactive Charts

Self Updating Charts

       -    we can apply very similar techniques to those of the self-updating pivot table
            to create self-updating charts and interactive charts

Step 1. Using offset and counta, create a defined name for the column “Random” that
brings in all of its elements.




In an easier to see view:

=OFFSET(Sheet1!$G$1,1,0,counta(Sheet1!$G:$G)-1,1)

Looking at each argument:

anchor = G1 I am anchoring off of the label of the data – this is my style, but it works
out well. I’ll show you why later.

rows_down = 1                 I do not want the label to be part of my data, just the values
columns_over = 0              I am staying in this column
height = # values – 1         I am counting all the values in column G, but I don’t want
                              to count the label
width = 1                     My data is only 1 column wide




                                                                                           25
Go back to the defined name dialog and click in your formula for random_graph. It
should highlight the data in that column, leaving off the label “Random.”




                                                                                    26
Step 2. Build a chart. On the series tab, we use the defined name (and the name of the
workbook) as the source of the data.




Click Finish and we’re all set.

Testing: Now, go back to Column G and add and take away values and see what
happens. The graph will grow and shrink automatically according to the size of the data.

Note that Excel requires that you put in the name of the workbook and an exclamation
point before the name of the data.




                                                                                         27
Interactive Charts

       - while it is nice to have the chart automatically show all data, that may not be the
desired behavior. We can make the graph interactive by playing around with the
parameters of the defined name “random_graph.”

Let’s recall those parameters:

anchor = G1
rows_down = 1
columns_over = 0
height = counta(Sheet1!$G:$G)-1
width = 1

By making rows_down and height dependent on cells we can manipulate, we gain
tremendous control over the graph.



Add the following two defined cells in K1 and K2:




                                                                                          28
Now edit the defined name “random_graph” to reference these.




In an easier to see view:

=OFFSET(Sheet1!$G$1,Sheet1!$K$1,0,Sheet1!$K$2,1)


Now, playing with changing the values in those cells will immediately change the look of
the graph. These values control the start and stop points of the data. Notice that there is
no additional logic beyond that which we provided. Changing graph_rows to 100 will
leave you with a lot of empty spots in your graph.




                                                                                        29
X-axis

To finish this graph off, we need to add the labels for the x-axis.

To do this, we simply take the formula we wrote for “random_graph” and re-anchor it in
column A. I always simply name mine “x_axis.”

The easiest way to do this is to:
1) bring up the defined name dialog box
2) click on “random_graph”
3) rename it “x_axis”
4) change the anchor parameter to A1 from G1
5) click Add
6) Click OK




                                                                                    30
Include this name in the graph as the X-axis labels and now the X-axis will move in
conjunction with your data.




                                                                                      31
The final product:




You should practice this with this by trying to include another series of data.

For example, try to add the “Ones” data to this graph as well, so that you’re graphing two
series of data, both controlled by cells K1 and K2.

While the set up of a graph like this is more involved, the payoffs come in how quickly it
can be updated or changed without having to go through the chart dialog boxes. A graph
like this is also a lot more secure.

We have graphs like this that use 10 data series and it is a lot easier for us to simply
change the number of rows or the starting point than it would be to go through and edit
10 series formulas, hoping not to miss one. Multiply that by the 20 spreadsheets we
update weekly, and the savings is well worth the couple of extra set up minutes.

I encourage you to also get creative with your input cells. With a MATCH function and a
drop down you can make the graph_start input a lot clearer by using actual dates. I will
send out an example of such a graph later.




                                                                                           32

Contenu connexe

Tendances

VLOOKUP HLOOKUP INDEX MATCH
VLOOKUP HLOOKUP INDEX MATCHVLOOKUP HLOOKUP INDEX MATCH
VLOOKUP HLOOKUP INDEX MATCHMridul Bansal
 
Working on MS-Excel 'FORMULA TAB'
Working on MS-Excel 'FORMULA TAB'Working on MS-Excel 'FORMULA TAB'
Working on MS-Excel 'FORMULA TAB'Pranav Kumar
 
Etech. mitch. [autosaved]
Etech. mitch. [autosaved]Etech. mitch. [autosaved]
Etech. mitch. [autosaved]MaridelBajeta
 
Excel Tutorials - VLOOKUP and HLOOKUP Functions
Excel Tutorials - VLOOKUP and HLOOKUP FunctionsExcel Tutorials - VLOOKUP and HLOOKUP Functions
Excel Tutorials - VLOOKUP and HLOOKUP FunctionsMerve Nur Taş
 
Advances in ms excel
Advances in ms excelAdvances in ms excel
Advances in ms excelMohit Kumar
 
10 Excel Formulas that will help you in any Job
10 Excel Formulas that will help you in any Job10 Excel Formulas that will help you in any Job
10 Excel Formulas that will help you in any JobHitesh Biyani
 
VLOOKUP Function - Marelen Talavera - Vivacious Analytic
VLOOKUP Function - Marelen Talavera - Vivacious AnalyticVLOOKUP Function - Marelen Talavera - Vivacious Analytic
VLOOKUP Function - Marelen Talavera - Vivacious AnalyticMaria Elena Acdol-Talavera
 
Using Excel Functions
Using Excel FunctionsUsing Excel Functions
Using Excel FunctionsGautam Gupta
 
On if,countif,countifs,sumif,countifs,lookup,v lookup,index,match
On if,countif,countifs,sumif,countifs,lookup,v lookup,index,matchOn if,countif,countifs,sumif,countifs,lookup,v lookup,index,match
On if,countif,countifs,sumif,countifs,lookup,v lookup,index,matchRakesh Sah
 
Creating Formulas in Excel
Creating Formulas in ExcelCreating Formulas in Excel
Creating Formulas in ExcelKim Estes
 
Microsoft Excel VLOOKUP Function
Microsoft Excel VLOOKUP FunctionMicrosoft Excel VLOOKUP Function
Microsoft Excel VLOOKUP FunctionExcel
 
Excel presentation
Excel presentationExcel presentation
Excel presentationDUSPviz
 
Excel for research
Excel  for researchExcel  for research
Excel for researchJamalBhai
 
03 Excel formulas and functions
03 Excel formulas and functions03 Excel formulas and functions
03 Excel formulas and functionsBuffalo Seminary
 

Tendances (20)

VLOOKUP HLOOKUP INDEX MATCH
VLOOKUP HLOOKUP INDEX MATCHVLOOKUP HLOOKUP INDEX MATCH
VLOOKUP HLOOKUP INDEX MATCH
 
Chap06 scr
Chap06 scrChap06 scr
Chap06 scr
 
Chapter.05
Chapter.05Chapter.05
Chapter.05
 
Working on MS-Excel 'FORMULA TAB'
Working on MS-Excel 'FORMULA TAB'Working on MS-Excel 'FORMULA TAB'
Working on MS-Excel 'FORMULA TAB'
 
Etech. mitch. [autosaved]
Etech. mitch. [autosaved]Etech. mitch. [autosaved]
Etech. mitch. [autosaved]
 
How to Use VLOOKUP in Excel
How to Use VLOOKUP in ExcelHow to Use VLOOKUP in Excel
How to Use VLOOKUP in Excel
 
Excel Tutorials - VLOOKUP and HLOOKUP Functions
Excel Tutorials - VLOOKUP and HLOOKUP FunctionsExcel Tutorials - VLOOKUP and HLOOKUP Functions
Excel Tutorials - VLOOKUP and HLOOKUP Functions
 
Formula in MS Excel
Formula in MS ExcelFormula in MS Excel
Formula in MS Excel
 
Ch1
Ch1Ch1
Ch1
 
Advances in ms excel
Advances in ms excelAdvances in ms excel
Advances in ms excel
 
10 Excel Formulas that will help you in any Job
10 Excel Formulas that will help you in any Job10 Excel Formulas that will help you in any Job
10 Excel Formulas that will help you in any Job
 
VLOOKUP Function - Marelen Talavera - Vivacious Analytic
VLOOKUP Function - Marelen Talavera - Vivacious AnalyticVLOOKUP Function - Marelen Talavera - Vivacious Analytic
VLOOKUP Function - Marelen Talavera - Vivacious Analytic
 
Mastering Excel Formulas and Functions
Mastering Excel Formulas and FunctionsMastering Excel Formulas and Functions
Mastering Excel Formulas and Functions
 
Using Excel Functions
Using Excel FunctionsUsing Excel Functions
Using Excel Functions
 
On if,countif,countifs,sumif,countifs,lookup,v lookup,index,match
On if,countif,countifs,sumif,countifs,lookup,v lookup,index,matchOn if,countif,countifs,sumif,countifs,lookup,v lookup,index,match
On if,countif,countifs,sumif,countifs,lookup,v lookup,index,match
 
Creating Formulas in Excel
Creating Formulas in ExcelCreating Formulas in Excel
Creating Formulas in Excel
 
Microsoft Excel VLOOKUP Function
Microsoft Excel VLOOKUP FunctionMicrosoft Excel VLOOKUP Function
Microsoft Excel VLOOKUP Function
 
Excel presentation
Excel presentationExcel presentation
Excel presentation
 
Excel for research
Excel  for researchExcel  for research
Excel for research
 
03 Excel formulas and functions
03 Excel formulas and functions03 Excel formulas and functions
03 Excel formulas and functions
 

Similaire à An Introduction To Array Functions

Introduction to micro soft Training ms Excel.ppt
Introduction to micro soft Training ms Excel.pptIntroduction to micro soft Training ms Excel.ppt
Introduction to micro soft Training ms Excel.pptdejene3
 
Useful Excel Functions & Formula Used everywhere.pptx
Useful Excel Functions & Formula Used everywhere.pptxUseful Excel Functions & Formula Used everywhere.pptx
Useful Excel Functions & Formula Used everywhere.pptxvanshikatyagi74
 
3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.ppt3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.pptAllanGuevarra1
 
3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.ppt3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.pptJosephIThomas
 
Libre Office Calc Lesson 4: Understanding Functions
Libre Office Calc Lesson 4: Understanding FunctionsLibre Office Calc Lesson 4: Understanding Functions
Libre Office Calc Lesson 4: Understanding FunctionsSmart Chicago Collaborative
 
E-Book 25 Tips and Tricks MS Excel Functions & Formulaes
E-Book 25 Tips and Tricks MS Excel Functions & FormulaesE-Book 25 Tips and Tricks MS Excel Functions & Formulaes
E-Book 25 Tips and Tricks MS Excel Functions & FormulaesBurCom Consulting Ltd.
 
Excel Tutorials - Random Value Selection from a List
Excel Tutorials - Random Value Selection from a ListExcel Tutorials - Random Value Selection from a List
Excel Tutorials - Random Value Selection from a ListMerve Nur Taş
 
Ms excel commands
Ms excel commandsMs excel commands
Ms excel commandsDiyaVerma14
 
MIRCROSOFT EXCEL- brief and useful for beginners by RISHABH BANSAL
MIRCROSOFT EXCEL- brief and useful for beginners by RISHABH BANSALMIRCROSOFT EXCEL- brief and useful for beginners by RISHABH BANSAL
MIRCROSOFT EXCEL- brief and useful for beginners by RISHABH BANSALRishabh Bansal
 
Excel Top 10 formula For The Beginners
Excel Top 10 formula For The BeginnersExcel Top 10 formula For The Beginners
Excel Top 10 formula For The BeginnersStat Analytica
 
MS_Excel_Module4.1 ffor beginners yo .pptx
MS_Excel_Module4.1 ffor beginners yo .pptxMS_Excel_Module4.1 ffor beginners yo .pptx
MS_Excel_Module4.1 ffor beginners yo .pptxshagunjain2k22phdcs0
 
functionsandformulas-131221213835-phpapp01.pdf
functionsandformulas-131221213835-phpapp01.pdffunctionsandformulas-131221213835-phpapp01.pdf
functionsandformulas-131221213835-phpapp01.pdfFranzLawrenzDeTorres1
 
GPP Spreadsheets
GPP SpreadsheetsGPP Spreadsheets
GPP Spreadsheetsmrcarty
 
Functions and formulas of ms excel
Functions and formulas of ms excelFunctions and formulas of ms excel
Functions and formulas of ms excelmadhuparna bhowmik
 

Similaire à An Introduction To Array Functions (20)

Introduction to micro soft Training ms Excel.ppt
Introduction to micro soft Training ms Excel.pptIntroduction to micro soft Training ms Excel.ppt
Introduction to micro soft Training ms Excel.ppt
 
Useful Excel Functions & Formula Used everywhere.pptx
Useful Excel Functions & Formula Used everywhere.pptxUseful Excel Functions & Formula Used everywhere.pptx
Useful Excel Functions & Formula Used everywhere.pptx
 
3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.ppt3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.ppt
 
3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.ppt3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.ppt
 
Libre Office Calc Lesson 4: Understanding Functions
Libre Office Calc Lesson 4: Understanding FunctionsLibre Office Calc Lesson 4: Understanding Functions
Libre Office Calc Lesson 4: Understanding Functions
 
Chapter9 more on database and sql
Chapter9 more on database and sqlChapter9 more on database and sql
Chapter9 more on database and sql
 
E-Book 25 Tips and Tricks MS Excel Functions & Formulaes
E-Book 25 Tips and Tricks MS Excel Functions & FormulaesE-Book 25 Tips and Tricks MS Excel Functions & Formulaes
E-Book 25 Tips and Tricks MS Excel Functions & Formulaes
 
Excel Tutorials - Random Value Selection from a List
Excel Tutorials - Random Value Selection from a ListExcel Tutorials - Random Value Selection from a List
Excel Tutorials - Random Value Selection from a List
 
Ms excel commands
Ms excel commandsMs excel commands
Ms excel commands
 
Advance excel
Advance excelAdvance excel
Advance excel
 
MA3696 Lecture 9
MA3696 Lecture 9MA3696 Lecture 9
MA3696 Lecture 9
 
MIRCROSOFT EXCEL- brief and useful for beginners by RISHABH BANSAL
MIRCROSOFT EXCEL- brief and useful for beginners by RISHABH BANSALMIRCROSOFT EXCEL- brief and useful for beginners by RISHABH BANSAL
MIRCROSOFT EXCEL- brief and useful for beginners by RISHABH BANSAL
 
Excel training
Excel trainingExcel training
Excel training
 
Excel Top 10 formula For The Beginners
Excel Top 10 formula For The BeginnersExcel Top 10 formula For The Beginners
Excel Top 10 formula For The Beginners
 
MS_Excel_Module4.1 ffor beginners yo .pptx
MS_Excel_Module4.1 ffor beginners yo .pptxMS_Excel_Module4.1 ffor beginners yo .pptx
MS_Excel_Module4.1 ffor beginners yo .pptx
 
functionsandformulas-131221213835-phpapp01.pdf
functionsandformulas-131221213835-phpapp01.pdffunctionsandformulas-131221213835-phpapp01.pdf
functionsandformulas-131221213835-phpapp01.pdf
 
GPP Spreadsheets
GPP SpreadsheetsGPP Spreadsheets
GPP Spreadsheets
 
Functions and formulas of ms excel
Functions and formulas of ms excelFunctions and formulas of ms excel
Functions and formulas of ms excel
 
Spreadsheets[1]
Spreadsheets[1]Spreadsheets[1]
Spreadsheets[1]
 
Excel Tips
Excel TipsExcel Tips
Excel Tips
 

An Introduction To Array Functions

  • 1. An Introduction to Array Functions, Offset Function, and Defined Formulas With Applications to Pivot Table and Chart Maintenance Barry Posterro – July 2009
  • 2. Array Functions Most functions we use take in multiple values and return one answer: Ex: = SUM (A1:A5) = AVERAGE(A1:A5) = A1 * A5 = A1 All return one value only and put that result in the cell where the function was written. An array function takes in a range of values (like A1:A5) and returns a range of values. Steps: 1) Select the entire range where you want the results to appear (results range) 2) Enter your formula 3) Finalize your formula by pressing CTRL-SHIFT-ENTER Ex: Simply reference the cells A1:A5 in cells A13:A17 2
  • 3. The results are: Things to notice: 1) The function has brackets around it. These are added by Excel and tell us that we entered an array function. 2) The function is the same in each of the cells A13:A17. This highlights the point that we only entered one formula, not five formulas. The only formula actually being calculated is the one in cell A13. Cells A14:A17 are just used for holding results, not calculating results. They contain the formula only as an auditing tool to tell us what function created these values. 3
  • 4. Array Function Security One of the nice things about array functions is that they add a level of security that we do not otherwise have if we’d entered in separate formulas. Attempt to delete cell A16. You should get the following error: You cannot break up an array formula after you have entered it. Excel enforces the integrity of the formula. This error is not limited to a delete attempt. Trying to edit any of the 5 cells will result in the same error. 4
  • 5. Editing an Array Function 1) Re-highlight the entire results range 2) Press F2 to enter the function edit mode 3) Edit formula 4) CTRL-SHIFT-ENTER Ex: Change the formula we already entered to reference column B1:B5 Notice that once you’ve edited the formula (but before CTRL-SHIFT-ENTER), the new domain will be outlined even while the results in A14:A17 are unchanged. Pressing CTRL-SHIFT-ENTER will cause the execution and those cells to update. Deleting an Array Function Select the entire results range (A13:A17) and press delete. To delete an array function, you must delete all of the cells it uses. 5
  • 6. Some Excel Array Functions – not so useful to us Excel has some array functions of its own. A lot of these are associated with statistics and data fitting. LINEST - fits data to a line y = mx+b. Given y’s and x’s it returns m and b. Ex: The results are 1 and 10, which make sense, since the columns differ by 10. It’s a good idea to read the help files associated with any new array function you are using from Excel’s library. This function returns its results in row form. If you had highlighted two stacked cells like C13 and C14, you would have gotten the result 1 twice. Like LINEST, there is also LOGEST, which estimates the fit y = b*m^x TREND – uses the linear estimate of LINEST to produce what the fitted values of the data would be. 6
  • 7. Some Excel Array Functions – useful to us Often we find ourselves in a situation where we receive data in one orientation (column) but need it in the other orientation (row) for what we need to do. The array function TRANSPOSE handles this: Ex: Take Column B and make it a row. We can also use this to transpose the entire table. This is our first use of a two dimensional array. Ex: 7
  • 8. OFFSET This is a very useful array function that the rest of this lecture will rely upon. It returns an array of values in the shape that the user specifies. It takes five inputs. OFFSET ( cell_anchor , rows_down, columns_right, height, width) The last two inputs are optional. They default to 1 if omitted. Ex: This example returns an array formed by: 1) relative to A1 2) move down 2 rows 3) move over 1 column - now we’re in cell B3 4) return a 4 row, 5 column array with cell B3 as the corner 8
  • 9. NOTES: If you want the cell_anchor to be the corner of your results, set the rows_down to zero and the columns_right to zero. Ex: You can also enter negative numbers for your rows_down or columns_right parameters. Ex: 9
  • 10. A height of 1 implies a row. A width of 1 implies a column. Ex: 10
  • 11. As mentioned earlier. Leaving off the last two parameters results in a single cell as those parameters each default to 1. Notice that if we’re only returning one cell, we do not need to use CTRL-SHIFT-ENTER and there are no brackets around the formula in the formula bar. Calculations So far, we’ve just been returning data, but we can also use OFFSET as the input to any function that takes in an array. For example, SUM or AVERAGE. Ex: 11
  • 12. This method allows us to make formulas in which the number of points to average can become one of the inputs to the formula. Let’s look at this with rolling averages. For each period, we take the average of the last number of months given in column A. 12
  • 13. OFFSET with TRANSPOSE Keep in mind that the display area must be the same shape as the array created by the offset function or you may get unexpected results. The following is what occurs if we try to put a row created by offset into a column: If a column is really what you want here, you need to invoke the transpose function. 13
  • 14. DEFINED NAMES While we employ using defined names to refer to cells in a workspace, the defined names capability of Excel also extends to formulas and constants (constants being a very simple formula.) Ex: Define the word “million” to be 1,000,000. 14
  • 15. Now, typing “=million” in any cell will return that value. And, we can use it in any formula like a variable. 15
  • 16. Likewise, we can define and name a formula. This formula sums up all of column B: Putting this name in any cell will return the sum of column B. 16
  • 17. COUNTA - simple function that returns how many values are present in a rang of cells Ex: First, let’s triple the size of the data. This function is the last key to the payoff of the earlier work we did. 17
  • 18. Self-Updating Pivot Table The argument of a pivot table’s range property is usually a set area of a spreadsheet. For example: As we know, if the dimensions of this area change, we need to reset the range argument of the pivot table. That is, if more rows or columns are added, we need to tell that to the pivot table. Using OFFSET, COUNTA and a defined name, we will make the argument of the pivot table’s domain a defined name that will never need to be updated. 18
  • 19. Step 1. Create an array that uses variable arguments for its size. In an easier to see view: =OFFSET(Sheet1!$A$1,0,0,counta(Sheet1!$A:$A),counta(Sheet1!$1:$1)) 19
  • 20. Pressing ADD, and then clicking into the formula bar, Excel will highlight the area that you are referencing with this formula. 20
  • 21. Step 2. Assign the name PT_data (or whatever you called this) to the range argument of the pivot table. Step 3. Click Finish and you are done. 21
  • 22. Now, going forward, as long as the data you want begins in the same corner as the data you are referencing with your defined name, PT_data, you never need to go through the Pivot Table options again to reset the range as more rows or columns are added. Let’s see that. Add another column of random data call “Garbage” and fill it in. Also, add another row called “Test.” 22
  • 23. Now, simply refresh your pivot table. The new field, Garbage, shows up now, and if you drop Dates into the row field, you’ll see Test now shows up as well. 23
  • 24. Notes: Beware of rogue data corrupting your defined name PT_data. Because the COUNTA is counting all values in the row and column, having stray values in those rows or columns will corrupt your dimensions. Also, make sure that you pick a column for COUNTA that will never be empty or your PT_data will not have as many rows as you need. The correct column to pick is not always the far left column. Also, while we call these “self-updating,” that only refers to the range. If data within your table changes, you still need to refresh your pivot table as you normally would. 24
  • 25. Self-Updating and/or Interactive Charts Self Updating Charts - we can apply very similar techniques to those of the self-updating pivot table to create self-updating charts and interactive charts Step 1. Using offset and counta, create a defined name for the column “Random” that brings in all of its elements. In an easier to see view: =OFFSET(Sheet1!$G$1,1,0,counta(Sheet1!$G:$G)-1,1) Looking at each argument: anchor = G1 I am anchoring off of the label of the data – this is my style, but it works out well. I’ll show you why later. rows_down = 1 I do not want the label to be part of my data, just the values columns_over = 0 I am staying in this column height = # values – 1 I am counting all the values in column G, but I don’t want to count the label width = 1 My data is only 1 column wide 25
  • 26. Go back to the defined name dialog and click in your formula for random_graph. It should highlight the data in that column, leaving off the label “Random.” 26
  • 27. Step 2. Build a chart. On the series tab, we use the defined name (and the name of the workbook) as the source of the data. Click Finish and we’re all set. Testing: Now, go back to Column G and add and take away values and see what happens. The graph will grow and shrink automatically according to the size of the data. Note that Excel requires that you put in the name of the workbook and an exclamation point before the name of the data. 27
  • 28. Interactive Charts - while it is nice to have the chart automatically show all data, that may not be the desired behavior. We can make the graph interactive by playing around with the parameters of the defined name “random_graph.” Let’s recall those parameters: anchor = G1 rows_down = 1 columns_over = 0 height = counta(Sheet1!$G:$G)-1 width = 1 By making rows_down and height dependent on cells we can manipulate, we gain tremendous control over the graph. Add the following two defined cells in K1 and K2: 28
  • 29. Now edit the defined name “random_graph” to reference these. In an easier to see view: =OFFSET(Sheet1!$G$1,Sheet1!$K$1,0,Sheet1!$K$2,1) Now, playing with changing the values in those cells will immediately change the look of the graph. These values control the start and stop points of the data. Notice that there is no additional logic beyond that which we provided. Changing graph_rows to 100 will leave you with a lot of empty spots in your graph. 29
  • 30. X-axis To finish this graph off, we need to add the labels for the x-axis. To do this, we simply take the formula we wrote for “random_graph” and re-anchor it in column A. I always simply name mine “x_axis.” The easiest way to do this is to: 1) bring up the defined name dialog box 2) click on “random_graph” 3) rename it “x_axis” 4) change the anchor parameter to A1 from G1 5) click Add 6) Click OK 30
  • 31. Include this name in the graph as the X-axis labels and now the X-axis will move in conjunction with your data. 31
  • 32. The final product: You should practice this with this by trying to include another series of data. For example, try to add the “Ones” data to this graph as well, so that you’re graphing two series of data, both controlled by cells K1 and K2. While the set up of a graph like this is more involved, the payoffs come in how quickly it can be updated or changed without having to go through the chart dialog boxes. A graph like this is also a lot more secure. We have graphs like this that use 10 data series and it is a lot easier for us to simply change the number of rows or the starting point than it would be to go through and edit 10 series formulas, hoping not to miss one. Multiply that by the 20 spreadsheets we update weekly, and the savings is well worth the couple of extra set up minutes. I encourage you to also get creative with your input cells. With a MATCH function and a drop down you can make the graph_start input a lot clearer by using actual dates. I will send out an example of such a graph later. 32