Excel Fomulae & Tricks

Embed Size (px)

Citation preview

  • 7/30/2019 Excel Fomulae & Tricks

    1/12

    Excel functions & tricks

    Transpose data table using the 'Offset' function

    =OFFSET(starting reference, rows offset, cols offset, [height], [width])

    INPUT

    100 0 1 2 3 4

    200 100 200 300 400 500300400 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 5Sheet2!$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.89444339

    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.468156669

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

    NOTE1Indirect returns a reference to a cell address specified as a string input. If the reference is to a singl

    value in that cell.

    NOTE2

    This technique allows you to easily copy your formula to new rows/columns as you add more works

    NOTE3

    This technique can also be used to transpose a table as an alternative to the OFFSET formula

    OUTPUT

    Validation lists which change depending on your selection in another columnCell information (eg. Filename)

    Sumproduct & conditional sumproduct

    Transpose data table using the 'offset' functionLookup values base on sheet name - ie. across multiple sheetsConvert to yearly total or yearly average

    Formulas that increment in blocksCurve fit coefficients

    Find first empty cell in a range

  • 7/30/2019 Excel Fomulae & Tricks

    2/12

    Convert to yearly total or yearly average

    Date Rate Cumm. Lookup date Cum. Annual

    [dd/mm/yyyy] [MMscf/d] [MMscf] [dd/mm/yyyy] [MMscf]

    1/1/2007 120 1/1/2007 03/1/2007 119 7080 1/1/2008 428825/1/2007 118 14339 1/1/2009 699557/1/2007 117 21537 1/1/2010 1094949/1/2007 116 28791 1/1/2011 150728

    11/1/2007 115 35867 1/1/2012 #N/A

    1/1/2008 0 428823/1/2008 0 428825/1/2008 112 428827/1/2008 111 497149/1/2008 110 56596

    11/1/2008 109 63306

    1/1/2009 108 699553/1/2009 107 763275/1/2009 106 828547/1/2009 105 893209/1/2009 104 95830

    11/1/2009 120 1021741/1/2010 118 1094943/1/2010 116 116456

    5/1/2010 114 1235327/1/2010 112 1304869/1/2010 110 137430

    11/1/2010 108 1441401/1/2011 106 1507283/1/2011 156982

    NOTE1

    Timesteps don't have to be uniform in size but the date at which the cummulativetotal 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.Annuallookup function with some resulting loss in accuracy

    NOTE2

    In this example rate the initial rate is assumed to continue for the duration of thattimestep. You could take the average of the initial and final rates but this wouldresult in errors during any shutdown, restart or new development. See the chartbelow

    INPUT CALCULATI

    110

    115

    120

    125Initial rate held for duration of timestep

    Avg rate assumed between timesteps

    Use of avg rate between timestepswould result in under-prediction in 2007

    and over-prediction in 2008

  • 7/30/2019 Excel Fomulae & Tricks

    3/12

    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

    Data No. rows to include 4

    12 ID Average3 0 2.54 1 6.55 2 10.5678 works by building an address range as a string using ADDRESS, conver

    9 and then evaluating it using the AVERAGE function101112

    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 fun

    Dummy equation used to generate some data:

    y = ax2 + bx +c

    a 3b 1

    c 4

    Data

    x x2 y

    -4 16 48-2 4 14

    0 0 44 16 566 36 1188 64 204

    Fitted coefficients

    a b c

    OUTPUT

    100

    105

    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

    0

    50

    100

    150

    200

    250

    -5 0

  • 7/30/2019 Excel Fomulae & Tricks

    4/12

    3 1 4

    NOTE1

    LINEST uses the least squares method to fit the coefficients. Because it returns an array of values,(select the cells under the data, enter the formula then hold down SHIFT & CONTROL as you clickOR you can use it inconjunction with the INDEX function - see below:

    a 3b 1

    c 4

    NOTE2

    This approach can also be used to fit an equation where there is more than one 'x' parameter - eg.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 parameters are not limited to 2, eg. In the above example you could have Pout = f(Pin, Rate, Rate

    Sumproduct & conditional sumproduct

    1 2 1*2 + 2*10 + 3*5 + 4*122 10 SumProduct where first col >23 5

    4 12 The conditional sumproduct works becauseFalse is the same as zero and by multiplyin

    Find first empty cell in a range

    =MATCH(lookup_value,lookup_array,match_type)

    1 0.6424362 Index of the first blank cell in the range is2 0.84580433 0.41584614 0.47132795 0.646107167

    8

    NOTE1

    Uses an array formula which evaluates all values in the range in a loop. When entering an array forwhen finished

    NOTE2

    This trick can be useful for determining the size of a list for example, when creating a dynamic rang

    NOTE3There is nothing special about the word "EMPTY" used in this formula - it is simply appended to anyand then the MATCH formula returns the index of the first instance it finds. Any word could be used

    6

    Validation lists which change depending on your selection in another column

    Data/Validation=OFFSET(starting reference, rows offset, cols offset, [height], [width])

  • 7/30/2019 Excel Fomulae & Tricks

    5/12

    =MATCH(lookup_value,lookup_array,match_type)

    Cascading input lists

    Country Country ID ListSize City Malaysia

    Germany 1 6 Berlin No. of entries 4

    New Zealand 3 4Auckland Johor BahruAustralia 2 6 Canberra Kuala Lumpur Malaysia 0 4 Kuala Lumpur KuchingGermany 1 6 Bremin PenangGermany 1 6 DusseldorfNew Zealand 3 4 ChristchurchNew 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

    \\vboxsrv\conversion_tmp\scratch_2\[167481493.xls.ms_office.xls]Sheet1

    Width (as integer)

    4.000

    Value type

    1 text

    b v lblank value label

    Bas

  • 7/30/2019 Excel Fomulae & Tricks

    6/12

    e cell then the formula will return the

    eets.

  • 7/30/2019 Excel Fomulae & Tricks

    7/12

    Year Days in year Avg.Rate

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

    2007 365 117.52008 366 74.02009 365 108.32010 365 113.02011 365 #N/A2012 366 #N/A

    ON

  • 7/30/2019 Excel Fomulae & Tricks

    8/12

    ting it to a range reference using INDIRECT

    ction

    5 10

  • 7/30/2019 Excel Fomulae & Tricks

    9/12

    it must be entered as an array formulaENTER)

    out = f(Pin, Rate)

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

    2) Pout = a.Pin + b.Rate + c.Rate2 + d

    8563

    a boolean expression which evaluates toby zero that term is effectively ignored

    6

    mula you must click Control-Shift-Enter

    (see example below)

    blank cell in the formula arrayas illustrated below:

  • 7/30/2019 Excel Fomulae & Tricks

    10/12

    Germany Australia New Zealand

    6 6 4

    Berlin Adelaide AucklandBremin Canberra ChristchurchDusseldorf Darwin DunedinFrankfurt Melbourne WellingtonKoeln PerthMuenchen Sydney

    data table

  • 7/30/2019 Excel Fomulae & Tricks

    11/12

    Random no.s

    6.90395324.8587859.22975

    16.4953922.3615533.89444

  • 7/30/2019 Excel Fomulae & Tricks

    12/12

    Random no.s

    0.82540.5523560.381157

    0.8930020.9779740.468157