You are on page 1of 12

Excel functions & tricks Transpose data table using the 'offset' function Lookup values base on sheet

name - ie. across multiple sheets Convert to yearly total or yearly average Formulas that increment in blocks Curve fit coefficients Sumproduct & conditional sumproduct Find first empty cell in a range Validation lists which change depending on your selection in another column Cell information (eg. Filename)

Transpose data table using the 'Offset' function =OFFSET(starting reference, rows offset, cols offset, [height], [width]) INPUT 100 200 300 400 500 0 100 1 200 OUTPUT 2 300 3 400 4 500

or without the column index numbers: 100 200 300

400

500

NOTE1 To transpose in the reverse direction change the offset from rows to cols

Lookup values based on sheet name - ie. across multiple sheets =INDIRECT(cell or range address as a text string, [type of reference, ie. A1 or R1C1]) =ADDRESS(row_num, column_num, [abs_num], [type of reference, ie. A1 or R1C1], [sheet name]) See input values on Sheets 2 & 3 0
Sheet2!$B$4

1
Sheet2!$B$5

2
Sheet2!$B$6

3
Sheet2!$B$7

4
Sheet2!$B$8

5
Sheet2!$B$9

Sheet2

6.9039534 24.858782 59.22974877


Sheet3!$B$4 Sheet3!$B$5 Sheet3!$B$6

16.49539 22.36154788
Sheet3!$B$7 Sheet3!$B$8

33.89444339
Sheet3!$B$9

Sheet3

0.8254003 0.5523564

0.38115681 0.8930017

0.9779739

0.468156669

or without the index numbers/headers: Sheet2 6.9039534 24.858782 59.22974877 16.49539 22.36154788 Sheet3 0.8254003 0.5523564 0.38115681 0.8930017 0.9779739

33.89444339 0.468156669

NOTE1 Indirect returns a reference to a cell address specified as a string input. If the reference is to a single cell then the formula will value in that cell. NOTE2 This technique allows you to easily copy your formula to new rows/columns as you add more worksheets. NOTE3 This technique can also be used to transpose a table as an alternative to the OFFSET formula

Convert to yearly total or yearly average INPUT Date


[dd/mm/yyyy]

CALCULATION Cumm.
[MMscf]

Rate
[MMscf/d]

Lookup date Cum. Annual


[dd/mm/yyyy] [MMscf]

1/1/2007 3/1/2007 5/1/2007 7/1/2007 9/1/2007 11/1/2007 1/1/2008 3/1/2008 5/1/2008 7/1/2008 9/1/2008 11/1/2008 1/1/2009 3/1/2009 5/1/2009 7/1/2009 9/1/2009 11/1/2009 1/1/2010 3/1/2010 5/1/2010 7/1/2010 9/1/2010 11/1/2010 1/1/2011 3/1/2011

120 119 118 117 116 115 0 0 112 111 110 109 108 107 106 105 104 120 118 116 114 112 110 108 106

7080 14339 21537 28791 35867 42882 42882 42882 49714 56596 63306 69955 76327 82854 89320 95830 102174 109494 116456 123532 130486 137430 144140 150728 156982

1/1/2007 1/1/2008 1/1/2009 1/1/2010 1/1/2011 1/1/2012

0 42882 69955 109494 150728 #N/A

NOTE1 Timesteps don't have to be uniform in size but the date at which the cummulative total is being looked up must always exist (eg. 01/01/2007, 01/01/2008 ...) However, if there are dates which are close to the date but slightly greater than it (eg. 04/01/2007) then you can change the 'FALSE' to 'TRUE in the Cum.Annual lookup function with some resulting loss in accuracy NOTE2 In this example rate the initial rate is assumed to continue for the duration of that timestep. You could take the average of the initial and final rates but this would result in errors during any shutdown, restart or new development. See the chart below
125
Initial rate held for duration of timestep

Avg rate assumed between timesteps

120 115 110


Use of avg rate between timesteps would result in under-prediction in 2007 and over-prediction in 2008

105

1/1/2007

3/1/2007

5/1/2007

7/1/2007

9/1/2007

1/1/2008

3/1/2008

5/1/2008

7/1/2008

9/1/2008

1/1/2009

5/1/2009

9/1/2009

1/1/2010

5/1/2010

9/1/2010

11/1/2007

11/1/2008

11/1/2009

Formulas that increment in blocks =INDIRECT(ref_text,a1) =ADDRESS(row_num,column_num,abs_num,a1,sheet_text) Example: Find the average of each block of 4 numbers INPUT OUTPUT

Data 1 2 3 4 5 6 7 8 9 10 11 12

No. rows to include ID 0 1 2 Average 2.5 6.5 10.5

works by building an address range as a string using ADDRESS, converting it to a range reference and then evaluating it using the AVERAGE function

Curve fit coefficients =LINEST(known_y's,known_x's,const,stats) Determine curve fit equation dynamically - without having to create a chart and use the trendline function Dummy equation used to generate some data: y = ax2 + bx +c a 3 b 1 c 4 Data x -4 -2 0 4 6 8 Fitted coefficients a

11/1/2010

x2 16 4 0 16 36 64

y 48 14 4 56 118 204
-5

1/1/2011 250 200 150 100


50

3/1/2009

7/1/2009

3/1/2010

7/1/2010

100

0
0

NOTE1 LINEST uses the least squares method to fit the coefficients. Because it returns an array of values, it must be entered as an a (select the cells under the data, enter the formula then hold down SHIFT & CONTROL as you click ENTER) OR you can use it inconjunction with the INDEX function - see below: a b c 3 1 4

NOTE2 This approach can also be used to fit an equation where there is more than one 'x' parameter - eg. Pout = f(Pin, Rate) Simply include all the columns containing 'x' data in the [known_x's] input range 2 Infact this is the same as what we have done in the above example - it just happens that the second x parameter (x ) is related X parameters are not limited to 2, eg. In the above example you could have Pout = f(Pin, Rate, Rate2) Pout = a.Pin + b.Rat

Sumproduct & conditional sumproduct 1 2 3 4 2 10 5 12 1*2 + 2*10 + 3*5 + 4*12 SumProduct where first col >2

The conditional sumproduct works because a boolean expression whic False is the same as zero and by multiplying by zero that term is effec

Find first empty cell in a range =MATCH(lookup_value,lookup_array,match_type) 1 2 3 4 5 6 7 8 0.6424362 0.8458043 0.4158461 0.4713279 0.6461071 Index of the first blank cell in the range is

NOTE1 Uses an array formula which evaluates all values in the range in a loop. When entering an array formula you must click Contr when finished NOTE2 This trick can be useful for determining the size of a list for example, when creating a dynamic range (see example below)

NOTE3 There is nothing special about the word "EMPTY" used in this formula - it is simply appended to any blank cell in the formula a and then the MATCH formula returns the index of the first instance it finds. Any word could be used as illustrated below: 6

Validation lists which change depending on your selection in another column Data/Validation =OFFSET(starting reference, rows offset, cols offset, [height], [width])

=MATCH(lookup_value,lookup_array,match_type) Cascading input lists Base data table

Country Country ID ListSize City Germany 1 6 Berlin New Zealand 3 4 Auckland Australia 2 6 Canberra Malaysia 0 4 Kuala Lumpur Germany 1 6 Bremin Germany 1 6 Dusseldorf New Zealand 3 4 Christchurch New Zealand 3 4 Dunedin

No. of entries

Malaysia 4 Johor Bahru Kuala Lumpur Kuching Penang

Can hide these columns NOTE1 Each of the equations used here are illustrated separately above.

Cell Information =CELL(info_type,reference) Filename \\vboxsrv\conversion_tmp\scratch_2\[167481493.xls.ms_office.xls]Sheet1 Width (as integer) 4.000 Value type b blank v value 1 text l label

reference is to a single cell then the formula will return the

you add more worksheets.

CALCULATION Year Days in year Avg.Rate


[yyyy] [---] [MMscf/d]

2007 2008 2009 2010 2011 2012

365 366 365 365 365 366

117.5 74.0 108.3 113.0 #N/A #N/A

ng ADDRESS, converting it to a range reference using INDIRECT

d use the trendline function

10

ns an array of values, it must be entered as an array formula ONTROL as you click ENTER)

ne 'x' parameter - eg. Pout = f(Pin, Rate)


2

ppens that the second x parameter (x ) is related to the first (x) out = f(Pin, Rate, Rate2) Pout = a.Pin + b.Rate + c.Rate2 + d

85 63

oduct works because a boolean expression which evaluates to ero and by multiplying by zero that term is effectively ignored

n entering an array formula you must click Control-Shift-Enter

ating a dynamic range (see example below)

mply appended to any blank cell in the formula array ny word could be used as illustrated below:

Base data table

Germany Australia 6 6 Berlin Adelaide Bremin Canberra Dusseldorf Darwin Frankfurt Melbourne Koeln Perth Muenchen Sydney

New Zealand 4 Auckland Christchurch Dunedin Wellington

Random no.s 6.903953 24.85878 59.22975 16.49539 22.36155 33.89444

Random no.s 0.8254 0.552356 0.381157 0.893002 0.977974 0.468157

You might also like