Vous êtes sur la page 1sur 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 OUTPUT

100 0 1 2 3 4
200 100 200 300 400 500
300
400 or without the column index numbers:
500 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 1 2 3 4 5
Sheet2.$B$4 Sheet2.$B$5 Sheet2.$B$6 Sheet2.$B$7 Sheet2.$B$8 Sheet2.$B$9
Sheet2 6.9039534 24.858782 59.22974877 16.49539 22.36154788 33.894443385

Sheet3.$B$4 Sheet3.$B$5 Sheet3.$B$6 Sheet3.$B$7 Sheet3.$B$8 Sheet3.$B$9


Sheet3 0.8254003 0.5523564 0.38115681 0.8930017 0.9779739 0.4681566691

or without the index numbers/headers:


Sheet2 6.9039534 24.858782 59.22974877 16.49539 22.36154788 33.894443385
Sheet3 0.8254003 0.5523564 0.38115681 0.8930017 0.9779739 0.4681566691

NOTE1
Indirect returns a reference to a cell address specified as a string input. If the reference is to a single cell then the for
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 CALCULATION

Date Rate Cumm. Lookup date Cum. Annual


[dd/mm/yyyy] [MMscf/d] [MMscf] [dd/mm/yyyy] [MMscf]
1/1/2007 120 1/1/2007
3/1/2007 119 7080 1/1/2008 42882
5/1/2007 118 14339 1/1/2009 69955
7/1/2007 117 21537 1/1/2010 109494
9/1/2007 116 28791 1/1/2011 150728
11/1/2007 115 35867 1/1/2012 #N/A
1/1/2008 0 42882
3/1/2008 0 42882
5/1/2008 112 42882
7/1/2008 111 49714
9/1/2008 110 56596
11/1/2008 109 63306
1/1/2009 108 69955
3/1/2009 107 76327
5/1/2009 106 82854
7/1/2009 105 89320
9/1/2009 104 95830
11/1/2009 120 102174
1/1/2010 118 109494
3/1/2010 116 116456
5/1/2010 114 123532
7/1/2010 112 130486
9/1/2010 110 137430
11/1/2010 108 144140
1/1/2011 106 150728
3/1/2011 156982

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
Use of avg rate between timesteps
would result in under-prediction in 2007
115 and over-prediction in 2008

110

105
125 Initial rate held for duration of timestep
Avg rate assumed between timesteps

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

110

105

100
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
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 No. rows to include 4


1
2 ID Average
3 0 2.5
4 1 6.5
5 2 10.5
6
7
8 works by building an address range as a string using ADDRESS, converting it to a range
9 and then evaluating it using the AVERAGE function
10
11
12

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 250
a 3
b 1
200
c 4

Data 150
x x2 y
-4 16 48
-2 4 14 100
0 0 4

50

0
-6 -4 -2 0 2 4 6 8
150

100

4 16 56
50
6 36 118
8 64 204
0
Fitted coefficients -6 -4 -2 0 2 4 6 8
a b c
3 1 4

NOTE1
LINEST uses the least squares method to fit the coefficients. Because it returns an array of values, it must be entere
(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 3
b 1
c 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
Infact this is the same as what we have done in the above example - it just happens that the second x parameter (x
X parameters are not limited to 2, eg. In the above example you could have Pout = f(Pin, Rate, Rate2) … Pout = a.Pi

Sumproduct & conditional sumproduct

1 2 1*2 + 2*10 + 3*5 + 4*12


2 10 SumProduct where first col >2
3 5
4 12 The conditional sumproduct works because a boolean expres
False is the same as zero and by multiplying by zero that term

Find first empty cell in a range


=MATCH(lookup_value,lookup_array,match_type)

1 0.9143896 Index of the first blank cell in the range is


2 0.5075015
3 0.8348261
4 0.1340729
5 0.7077001
6
7
8

NOTE1
Uses an array formula which evaluates all values in the range in a loop. When entering an array formula you must cl
when finished

NOTE2
This trick can be useful for determining the size of a list for example, when creating a dynamic range (see example b

NOTE3
There is nothing special about the word "EMPTY" used in this formula - it is simply appended to any blank cell in the
and then the MATCH formula returns the index of the first instance it finds. Any word could be used as illustrated be
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 Malaysia


Germany 1 6 Berlin No. of entries 4
New Zealand 3 4 Auckland Johor Bahru
Australia 2 6 Canberra Kuala Lumpur
Malaysia 0 4 Kuala Lumpur Kuching
Germany 1 6 Bremin Penang
Germany 1 6 Dusseldorf
New Zealand 3 4 Christchurch
New Zealand 3 4 Dunedin

Can hide these columns

NOTE1
Each of the equations used here are illustrated separately above.

Cell Information
=CELL(info_type,reference)

Filename
'file:///conversion/tmp/scratch/38701275.xls'#$Sheet1

Width (as integer)


4.000

Value type
1 text
b v l
blank value label
heet name])

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

more worksheets.
CALCULATION

Year Days in year Avg.Rate


[yyyy] [---] [MMscf/d]
2007 365 117.5
2008 366 74.0
2009 365 108.3
2010 365 113.0
2011 365 #N/A
2012 366 #N/A
ESS, converting it to a range reference using INDIRECT

trendline function

50

00

50

00

50

0
0 2 4 6 8 10
50

00

50

0
0 2 4 6 8 10

ay of values, it must be entered as an array formula


as you click ENTER)

ameter - eg. Pout = f(Pin, Rate)

at the second x parameter (x2) is related to the first (x)


n, Rate, Rate2) … Pout = a.Pin + b.Rate + c.Rate2 + d

85
63

rks because a boolean expression which evaluates to


by multiplying by zero that term is effectively ignored

g an array formula you must click Control-Shift-Enter

ynamic range (see example below)


ended to any blank cell in the formula array
ould be used as illustrated below:

Base data table

Germany Australia New Zealand


6 6 4
Berlin Adelaide Auckland
Bremin Canberra Christchurch
Dusseldorf Darwin Dunedin
Frankfurt Melbourne Wellington
Koeln Perth
Muenchen Sydney
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

Vous aimerez peut-être aussi