You are on page 1of 18

1/11/13

All skills | CIMA Spreadsheet Skills

CIMA Spreadsheet Skills


Browse this site on your mobile phone or tablet to experience our web app

CA T E G O RY A RCHI V E S : A L L S K I L L S

SUMPRODUCT
Posted on January 8, 2013 Query I have been told by my colleagues that SUMPRODUCT is a very versatile Excel function, but I am not sure I understand its full capabilities. Would you mind shedding some light please? Advice I have mentioned SUMPRODUCT in passing before (for example July 2009s article). However, for the purposes of self-containment, let me recap on the basics first. It should be noted that all of the examples below are included in the attached Excel file. Basic functionality At first glance, SUMPRODUCT(vector1,vector2,) appears quite humble. Before showing an example, though, look at the syntax carefully: a vector for Excel purposes is a collection of cells either one column wide or one row deep. For example, A1:A5 is a column vector, A1:E1 is a row vector, cell A1 is a unit vector and the range A1:E5 is not a vector (it is actually an array, but more on that later). The ranges must be contiguous this basic functionality uses the comma delimiter (,) to separate the arguments (vectors). Unlike most Excel functions, it is possible to use other delimiters, but this will be revisited shortly below. Consider the following sales report: Example sales report

The sales in column H are simply the product of columns F and G, e.g. the formula in cell H12 is simply =F12*G12. Then, to calculate the entire amount cell H23 sums column H. This could all be performed much quicker using the following formula: =SUMPRODUCT(F12:F21,G12:G21) i.e. SUMPRODUCT does exactly what it says on the tin: it sums the individual products. Example sales report SUMPRODUCT solution

www.cimaapps.com/spreadsheetskills/?cat=5

1/18

1/11/13

All skills | CIMA Spreadsheet Skills

Dealing with multiple criteria Where SUMPRODUCT comes into its own is when dealing with multiple criteria. This is done by considering the properties of TRUE and FALSE in Excel, namely: TRUE*number = number (e.g. TRUE*7 = 7); and FALSE*number = 0 (e.g. FALSE*7=0). Consider the following example: Example dummy database

We can test columns F and G to check whether they equal our required values. SUMPRODUCT could be used as follows to sum only sales made by Business Unit 1 for Product Z, viz. =SUMPRODUCT((F12:F21=1)*(G12:G21=Z)*H12:H21). For the purposes of this calculation, (F12:F21=1) replaces the contents of cells F12:F21 with either TRUE or FALSE depending on whether the value contained in each cell equals 1 or not. The brackets are required to force Excel to compute this first before cross-multiplying. Similarly, (G12:G21=Z) replaces the contents of cells G12:G21 with either TRUE or FALSE depending on whether the value Z is contained in each cell. Therefore, the only time cells H12:H21 will be summed is when the corresponding cell in the arrays F12:F21 and G12:G21 are both TRUE, then you will get TRUE*TRUE*number, which equals the said number. Notice that SUMPRODUCT is not an array formula (i.e. you do not use CTRL+SHIFT+ENTER; please see January 2010s article on arrays), but it is an array function, so again it can use a lot of memory making the calculation speed of the file slow down. Note also that this uses the * delimiter rather than the comma, analogous to TRUE*number, etc. If you were to use the comma delimiter instead, the syntax would have to be modified thus: =SUMPRODUCT((F12:F21=1),(G12:G21=Z),H12:H21). Minus minus? The first negation in front of the brackets converts the array of TRUEs and FALSEs to numbers, albeit substituting -1 for TRUE and 0 for FALSE. The second minus sign negates these numbers so that TRUE is effectively 1, rather than -1, whilst FALSE remains equals to zero. This variant often confuses end users which is why I recommend the first version described above. More elaborate uses You can get more and more sophisticated: Equality example

www.cimaapps.com/spreadsheetskills/?cat=5

2/18

1/11/13

All skills | CIMA Spreadsheet Skills

In this scenario, the end user pays invoices only where the invoice number matches the number checked on an authorised list. In the illustration above, two invoices (highlighted in red) do not match. SUMPRODUCT can be used to sum the authorised amounts only as follows: =SUMPRODUCT((F12:F21=G12:G21)*H12:H21) The argument in brackets only gives a value of TRUE for each row when the values in columns F and G are identical. Another example includes neither the comma nor the multiplication delimiter: Number of unique items

The formula in cell G29 in this illustration is: =SUMPRODUCT((F12:F21<>")/COUNTIF(F12:F21,F12:F21&")) which is so intuitively clear there is no need for an explanation(!) Jokes aside, a full explanation can be found in the attached Excel file. Comprehensive example

www.cimaapps.com/spreadsheetskills/?cat=5

3/18

1/11/13

All skills | CIMA Spreadsheet Skills

(Click on image to enlarge) So far, I have only considered SUMPRODUCT with vector ranges. Using the multiplication delimiter (*), it is possible to use SUMPRODUCT with arrays (an array is a range of cells consisting of both more than one row and more than one column). In the above example, SUMPRODUCT has been used in its elementary form in cells I36:N36. For example, the formula in cell I36 is: =SUMPRODUCT($H$32:$H$35,I$32:I$35) and this has then been copied across to the rest of the cells. To calculate the total costs of this retail bank example, this could be calculated as: =SUMPRODUCT($I$36:$N$36,$I$21:$N$21) However, the formula in cell I41 appears more and unnecessarily complicated: =SUMPRODUCT($H$32:$H$35*$I$32:$N$35*$I$21:$N$21) The use of the multiplication delimiter is deliberate (the formula will not work if the delimiters were to become commas instead). It should be noted that this last formula is essentially =SUMPRODUCT(Column_Vector*Array*Row_Vector) where the number of rows in the Column_Vector must equal the number of rows in the Array, and also the number of columns in the Array must equal the number of columns in the Row_Vector. The reason for this extended version of the formula is in order to divide the costs between Budget and Standard costs in my example. For example, the formula in cell J41 becomes: =SUMPRODUCT($H$32:$H$35*$I$32:$N$35*$I$21:$N$21*($G$32:$G$35=J$40)) ie the formula is now of the form =SUMPRODUCT(Column_Vector*Array*Row_Vector*Condition) where Condition uses similar logic to the TRUE / FALSE examples detailed earlier. This is a powerful concept that can be used to replace PivotTables (see May 2009s article), for instance. Word to the wise There are valid / more efficient alternatives to SUMPRODUCT in some instances. For example, dealing with multiple criteria for vector ranges, the SUMIFS function is six times faster, but will only work with Excel 2007 and later versions. Over-use of SUMPRODUCT can slow the calculation time down of even the smallest of Excel files. Used sparingly, however, it can be a highly versatile addition to the modellers repertoire. It is a sophisticated function, but once you understand how it works, you can start to use SUMPRODUCT for a whole array of problems (pun intended!)

www.cimaapps.com/spreadsheetskills/?cat=5

4/18

1/11/13

All skills | CIMA Spreadsheet Skills


Posted in All skills, Excel functions | Leave a reply

AutoFilter and Advanced Filter


Posted on January 8, 2013 Query I keep using AutoFilter for data analysis but I cant help noticing theres an Advanced Filter too. What does it do? Am I using AutoFilter correctly? Advice We often filter data using Excel. For many, the AutoFilter seems to provide sufficient options, or else they will interrogate the data using PivotTables (see May 2009s article for further information). Sometimes, more complex analysis is required. One way this may be conducted is with Advanced Filters, but before I talk about this functionality, let me recap the AutoFilter. AutoFilter In Excel 2007 and later versions, filtering may be performed by creating a table first (see May 2011s article for more details). If your data is not in an Excel table, or you are using Excel 2003 and earlier versions, then you should construct your database first as follows: headings: in the row immediately above the data, enter a heading for each column no blank rows or columns: you can leave blank cells in a row or column but make sure that there are no completely blank rows or columns within the database separate the data from the rest of your spreadsheet: keep the database on a worksheet away from other data. Imagine the database is an island with a moat of blank cells entirely surrounding the dataset.

Example database layout

To activate the AutoFilter, the top row (the headings) should be selected, and then:

Excel 2003 and earlier From the drop down menus, go to Data -> Filter -> AutoFilter (ALT + D + F + F).

Excel 2007 and later On the Data tab of the ribbon, go to the Sort & Filter group and click the AutoFilter icon (ALT + A + T).ALT + D + F + F still works.

www.cimaapps.com/spreadsheetskills/?cat=5

5/18

1/11/13

All skills | CIMA Spreadsheet Skills

The database may now be filtered to select data that meets certain condition by clicking on the drop down arrows to the right of each heading, viz.

Data filtering

This could be summarised in a PivotTable too, and the attached Excel workbook (.xls 1MB) provides an illustration of this. The arrows will change appearance when a filter has been applied to that column. The filter can be removed by clicking on the filter button once more, or you can clear all filters in one bound (in any version of Excel) using the keyboard shortcut ALT + D + F + S (which is Show All in Excel 2003 / earlier and Clear in Excel 2007 / later). This Excel feature does have limitations, however. Filtering based on more complex criteria may not be possible and data may be filtered based only on visible cells:

Filter visible data only

Moreover, there is an upper limit on the number of categories that may be filtered. For Excel 2003 and earlier versions, this limit is 1000, but this has been increased ten-fold to 10,000 for Excel 2007 (although Excel 2010 only appears to show 9998) and later versions:

Excel 2003 and earlier

Excel 2007 and later

www.cimaapps.com/spreadsheetskills/?cat=5

6/18

1/11/13

All skills | CIMA Spreadsheet Skills

For many, the capabilities of AutoFilter far exceed its limitations, and sufficient analysis can be performed with this feature. Sometimes, however, the following tool may prove more bountiful Advanced filter Using the same database setup, it is possible to undertake more complicated analysis using he Advanced Filter. First select the database, and then:

Excel 2003 and earlier From the drop down menus, go to Data -> Filter -> Advanced Filter (ALT + D + F + A).

Excel 2007 and later On the Data tab of the ribbon, go to the Sort & Filter group and click the Advanced Filter icon (ALT + A + Q).ALT + D + F + A still works.

This activates the following dialog box:

Advanced filter dialog box

It is very simple to use (it is the criteria which takes practice!) The List Range is simply the database to be reported upon including the top row

www.cimaapps.com/spreadsheetskills/?cat=5

7/18

1/11/13

All skills | CIMA Spreadsheet Skills


headings. It does not have to include all columns but should include all rows. Data may be filtered either in place or else the database may be copied to another location for ease of use (if the Copy to another location option is selected to facilitate this, the Copy to: range becomes active). The Unique records only checkbox is very useful as it will automatically eliminate any duplicates from the analysis. However, a duplicate occurs only when the complete record (ie the values in all columns specified in the List range) appears elsewhere in the database. This just leaves the Criteria range:, which as I alluded to above, is where the magic happens. A criteria range consists of a minimum of two rows as follows:

Example criteria table

The first row is always the headings row. It does not always have to be populated, but if the table is to include criteria based on a certain field (column of data), the heading must match the heading in the source data table precisely. The second and subsequent rows contain the criteria to be evaluated. These cells may be blank, contain formulae, values or text. Criteria on the same row must all be true to be filtered, whereas criteria on different rows are alternative criteria that may be met for filtering purposes. In this illustration above, for a record to pass filtering it must either meet criteria 1, 2 and 3 simultaneously or else criteria 4, 5 and 6 concurrently. Real-life examples might include the following:

March sales for the north division

Camera sales for February and April 2012

With a little imagination, reports can be constructed identifying duplicate data, top ten sales and even incomplete records (see the attached Excel workbook (.xls 1MB) for illustrations). Word to the wise Both of these types of filtering have limitations. One key restriction is that if the source database were to change, just like PivotTables, the filter reports would need to be re-run. Unlike PivotTables, however, there is no Refresh All option. If source data is likely to change, it may be better to consider alternative solutions to working with multiple criteria (please see my July 2009 article on multiple criteria). Posted in All skills, Excel functionalities | Leave a reply

Modified internal rate of return (MIRR)


Posted on January 8, 2013 Query Further to your article on internal rates of return (IRRs), you mentioned that every time the cash flow to be assessed changes sign there could be another solution. I have such a cash flow and I am looking for an objective way to analyse the return. Do you have any suggestions? More than one solution I refer you to my September 2011 article on problems with calculating IRRs in Excel. As the readers query states, there can be more than one IRR. Every time a cashflow series changes sign (ie goes from positive to negative or vice versa) there is potentially another solution. Consider the following: Multiple solutions

www.cimaapps.com/spreadsheetskills/?cat=5

8/18

1/11/13

All skills | CIMA Spreadsheet Skills

Here, prompted by a guess in the XIRR function (albeit of the other solution 21.43%), the two common Excel functions XIRR and IRR return the two IRRs associated with this cashflow scenario. It is important to not only check that an IRR gives an NPV of zero but that it is also the correct one in the circumstances. This is the first problem with the concept of IRR. However, before we look at an objective way to generate just one meaningful solution for analysis, Id like to consider another key issue. Forget the almost nonsensical IRR of 970.86% quoted in the above example. The other solution, 21.43%, seems more realistic, yes? As explained in my previous article, the internal rate of return (IRR) is the name given to the discount rate that makes the net present value (NPV) of a range of cashflows zero. For example, if I invest USD100 now and receive USD121 back in two years time, this would give me an annual IRR of 10% since: (USD100) + PV(USD121) = (USD100) + USD121 / (1 + 10%)2 = (USD100) + USD100 NPV = 0 It is nothing more than this. Put simply, if all cash required is borrowed at 21.43% and all surplus cash is reinvested at 21.43%, my project would neither create nor destroy cash value. Wait a minute. Reinvest at 21.43%? If I could find a risk free investment returning this sort of money, I would be depositing my pension in it, never mind stakeholders funds. The symmetry of the finance rate (cost of borrowing, typically the weighted average cost of capital) and the reinvestment rate (the return surplus funds can generate) is usually an absurd notion in the real world: if gains could be made in a free market, the principle of arbitrage would soon erode this advantage. If we are looking for a measure to address the multiple solutions issue of IRR, perhaps we should also ensure it considers the fact that finance rates tend to be greater than reinvestment rates. Walkthrough example I am going to suggest the alternative measure of modified internal rate of return (MIRR). To explain how this works, I will be using the following example, which is included in the attached Excel file (94KB). Consider the following assumptions: MIRR assumptions (click to enlarge)

www.cimaapps.com/spreadsheetskills/?cat=5

9/18

1/11/13

All skills | CIMA Spreadsheet Skills

Lets keep this example nice and simple. Here, I have assumed a finance rate of 12%, a reinvestment rate of a more realistic 8% (say) and cash flows generated periodically at 11 points of time (time 0 being now to time 10 being ten periods from now). Notice that the cash flows change sign a total of five times, which means there could be potentially five different IRRs. This is the reason for the guess cell (G16) in the illustration above. The IRR formula in cell G24 is: =IRR(H22:R22,Guess) where changing the value of guess may cause the IRR calculated to vary (ie generate an alternative solution). The MIRR calculation (cell G25) is simply =MIRR(H22:R22,Finance_Rate,Reinvestment_Rate) where the Finance_Rate is entered in cell G13 and the Reinvestment_Rate is entered in cell G14. The formula for MIRR is defined as follows: MIRR formula

where: NPV() is the Excel NPV function rrate is the reinvestment rate frate is the finance rate values[positive] is the positive values in the array only values[negative] is the negative values in the array only n is the number of periods. This formula will always give the same value regardless of the number of changes of sign in the cash flow. It also takes into account the disparity between reinvestment and finance rates. It ticks the boxes, so the only question is: what on earth does it do? Its quite simple actually in concept. Lets ignore the formula and perform the calculation manually with the example above. The first problem we have is the number of sign changes (five). To get an objective measure, we need just the one change of sign to ensure a unique solution. How do we do that? To begin with, the cash flows should be split in two as follows: Splitting the cash flow (click to expand)

The attached Excel file (94KB) clearly shows how this breakdown was arrived at using MAX() and MIN() functions. The intention now is to replace the values in one or both rows by an equivalent single positive or negative number. This is not simply the summation

www.cimaapps.com/spreadsheetskills/?cat=5

10/18

1/11/13
next period using the above assumptions).

All skills | CIMA Spreadsheet Skills


of the rows as this does not take into account the time value of money (eg USD100 reinvested would be worth USD108 = USD100 x (1 + 8%) in the

To work out what the discount factor should be, we need to determine the appropriate rate (finance rate for negative cash flows and reinvestment rate for positive cash flows) and at what point in time the cash flows are to be collated. We do this using the following table: Calculating the discount factors (click to expand)

The finance rate calculates the appropriate discount factor required to generate the present values for time 0 (ie the value of all negative cash flows as if they had arisen in the first period). This is because for most projects, companies will invest first (negative cash flows in early periods) to receive positive cash flows in later periods. For example, the time 2 factor (0.797, cell J33) is calculated as 1/1.122, ie discounting for two periods at the finance rate of 12%. The reinvestment rate calculates the appropriate discount factor required to generate the present values for the final period (here, time 10 or the 11th period, ie the value of all positive cash flows as if they had arisen in the last period). As before, this is because for most projects, companies will invest first (negative cash flows in early periods) to receive positive cash flows in later periods including the final period. For example, the time 7 factor (1.260, cell O34) is calculated as 1.083, ie inflating for three periods (= 10 7) at the reinvestment rate of 8%. Now, we simply cross multiply the discount factors (rows 33 and 34 in our example) by the split cash flows (rows 40 and 41), viz. Calculating the present values (click to expand)

The negative numbers after time 0 become smaller (reflecting the discounting), whereas positive cash flows are increasingly inflated the earlier they are to the final period (time 10). We now have three alternative cash flows we can consider: 1. Aggregate the investment (negative) cash flows only. 2. Aggregate the returns (positive cash flows) only. 3. Aggregate both the investment cash flows and the returns. Each of these options will only create one change of sign and take into account the disparate discount rates. I now consider each one in turn. 1. Aggregate the investment (negative) cash flows only The attached Excel file (94KB) calculates the following cash flow: Aggregation of investments only (click to expand)

Row 85 shows a negative cash flow in the first period (being the sum of row 47) with non negative cash flows thereafter (from row 41). Having zero in a period does not constitute a change of sign, but these cells must be zero rather than blank else the Excel functions will not calculate correctly (see September 2011s IRR article for further details).

www.cimaapps.com/spreadsheetskills/?cat=5

11/18

1/11/13

All skills | CIMA Spreadsheet Skills


Note that while the IRR changes slightly from the original calculation, the MIRR is precisely the same. This IRR is unique (only one change of sign). 2. Aggregate the returns (positive cash flows) only The following cash flow may be calculated: Aggregation of returns only

Row 96 shows several negative cash flows (referenced to row 40) with a non negative cash flow in the final period (being the sum of row 48). Note that again the IRR changes from the original calculation (it is reduced since all positive cash flows have been moved to the final period), the MIRR is precisely the same. As before, this IRR is unique (only one change of sign). 3. Aggregate both the investments and the returns (MIRR approach) This is the first cash flow shown in the outputs section of the attached Excel file (94KB):

Aggregation of both investments and returns (MIRR approach; click to expand)

Row 73 contains only two non zero flows: the present value of all investments at time 0 and the future value of all returns at time 10. As before, for this to work correctly, the interim period cash flows must be zero rather than blank. As above, the IRR will be unique, but this time the IRR equals the MIRR. This is how the MIRR is calculated. Indeed, cell G77 contains an alternative method of calculation, the exponential growth approach, calculated as: =(32,366/12,701)1/10 This is essentially the MIRR formula: MIRR formula

where: NPV() is the Excel NPV function rrate is the reinvestment rate frate is the finance rate values[positive] is the positive values in the array only values[negative] is the negative values in the array only n is the number of periods. Using the formula, MIRR is arguably quicker to calculate than IRR, more objective (only one solution) and takes into account the differing rates implicit in the cash flows. MIRR is usually lower than IRR (assuming the reinvestment rate will be lower than the finance rate), unless the

www.cimaapps.com/spreadsheetskills/?cat=5

12/18

1/11/13

All skills | CIMA Spreadsheet Skills


reinvestment rate equals the finance rate, whereby altering the cash flows as depicted above will neither affect the NPV nor the IRR. The MIRR is often seen as a financial measure of an investments attractiveness. It is used frequently in capital budgeting to rank alternative investments of similar size (although this may not always be an appropriate approach: NPV or NPV per USD invested (the so called bang for buck key factor analysis) may be more suitable metrics). There is much confusion about what the reinvestment rate implies. However, both the NPV and the IRR techniques assume the cash flows generated by a project are reinvested within that same project. This is not always the case: often, they are often reinvested elsewhere within the business and it is not a necessary assumption that the firm is capable of generating that IRR elsewhere. Indeed, one implication of the MIRR is that the project is not capable of generating cash flows as predicted and that the projects NPV is overstated. Posted in All skills, Excel functions | Leave a reply

Modelling actual versus budget


Posted on January 8, 2013 Query I have to keep track of how actual data compares to the original budget / forecast data and report the variances. Do you have any tips as to how to structure my spreadsheet? Advice This is an area where I have seen modellers get into a mess with alarming regularity. However, with a little thought at the outset, the OFFSET function (also see April 2009s article) can prove very useful. OFFSET remembered As a reminder, the syntax for OFFSET is as follows: OFFSET(Reference,Rows,Columns,[Height],[Width]). The arguments in square brackets (Height and Width) can be omitted from the formula and will be for the entirety of this article. In its most basic form, OFFSET(Ref,x,y) will select a reference x rows down (-x would be x rows up) and y rows to the right (-y would be y rows to the left) of the reference Ref. To assist with this months topic, please feel free to download the attached Excel file (239KB). Setting up the original budget / forecast data This can simply be typed in, but given the what if analysis demanded of most finance professionals these days, I would be tempted to set it up in a scenario table, viz. Setting up a scenario table

This method allows for various scenarios to be modelled easily with a different set of input data inserted into each column (from column L onwards in this illustration). A selector (cell J11 in the figure above) is used to select the active scenario, which may be highlighted using conditional formatting (see August 2009s article). The data used to drive the model is then highlighted in column J (here, emphasised in yellow) using the following formula for cell J14 for example: =OFFSET(K14,,$J$11) In other words, this formula looks up data x columns to the right of column K, where x is specified as the value input in cell J11 (here, this value is 4

www.cimaapps.com/spreadsheetskills/?cat=5

13/18

1/11/13
so column Os data is selected).

All skills | CIMA Spreadsheet Skills

Clearly, using a columnar approach here makes it very straightforward to set the various scenarios out. However, most financial models are displayed with dates going from left to right across columns rather than down the page using rows. This requires us to transpose the data, and again we may use OFFSET to flip the data: Transposing the data

Here, the period numbers specified in row 31 make it easy for us to transpose the data. For example, the formula in cell L34 would be: =OFFSET($J$13,L$31,) ie insert the data x rows down from cell J13 in the first graphic, where x is again specified as the value input in cell J11. Take care, however, if using an amount followed by growth rates approach for forecast / budget data. The amounts using these examples should be as follows: Calculating the budget / forecast data

The correct formula here is: =IF(L$31=1,L$34,K36*(1+L$34)) for cell L36 (say), ie if it is the first period take the amount, otherwise take the amount calculated in the preceding period and multiply it by (1 + growth rate specified in the current period not the next period). Including actual data When actual data is input into a model, it frequently replaces the original information and therefore management loses the ability to see how accurate forecasts were originally and how budgeting may be improved. One way round this would be to simply have actuals as one of the scenarios so that all forecasts are retained. This is often all that is required, and if so, simply do that. However, often we may wish to undertake variance analysis by comparing actual data with the original budgeted information. In this case, I would suggest the following approach. Comparing actual data with the original budgeted information

Rows 9 to 13 of this illustration simply reiterate the calculations already detailed above regarding the original forecasting. Note row 18 however: this is where actual data is added instead. In my example, I simply use hard coded inputs for my data, but it only requires a simple variation to this methodology to revise growth rates, etc. Using my logic, we simply use actual data where it is available; otherwise we fall back on the original data and calculations. This is achieved by the

www.cimaapps.com/spreadsheetskills/?cat=5

14/18

1/11/13

All skills | CIMA Spreadsheet Skills


formula in row 23 in my example, which is (for cell L23): =IF(L$18<>",L$18,IF(L$3=1,L$11,K23*(1+L$11))), ie, if there is data in the corresponding cell in row 18 use it; if not, if it is the first period take the original input value, otherwise simply inflate the prior period amount by (1 + growth rate for that period). It may include a nested IF statement, but it is still a relatively simple and straightforward calculation. Presentation of the outputs Performing the calculations is only half of the battle. Modellers often have difficulty comparing the original outputs with the reforecast counterparts in an effective and efficient manner. If sufficient, the following would be relatively straightforward: Comparing actual data with the original budgeted information

This is very easy to put together, but alas, more often than not, the following presentation is required by senior management instead: Typical variance analysis output

Seem familiar? I have been a model reviewer for many a year and seen this type of output on a regular basis. Many senior management teams like it this way and it is not my role to challenge the status quo well, at least not on this forum anyway! The problem with this layout, however, is that it lends itself to promoting poor practice. Models constructed in this way require a large number of unique formulae across a row, which in turn slows down model construction and increases the potential for mistakes, such as referencing errors. If you have to use this layout, creating the simple summary elsewhere (maybe on an input page), Interim calculation

inserting two additional lines on the output sheet and using the OFFSET function once more may make your potential troubles a thing of the past, viz . Revised outputs

The interim calculation is straightforward, summarising the original calculations, the revised calculations and the difference (variance) between them. Looking at the attached Excel file, you will see that each row of the revised output example contains only one unique formula copied across, making it easy to edit, extend and review. This is achieved by adding two rows: Selector (row 7): identifies whether the column should be reporting the budget information, the actual data or the variance. The equation used makes

www.cimaapps.com/spreadsheetskills/?cat=5

15/18

1/11/13

All skills | CIMA Spreadsheet Skills


use of the MOD(number,divisor) function (see November 2011s article): =MOD(L$4,List_Depth)+IF(MOD(L$4,List_Depth)=0,List_Depth,0), List_Depth is the number of selections (Budget, Act / Refcast, Variance) permissible in this case three. =MOD(L$4,List_Depth) takes the counter and converts each one to 1, 2 and 0 (ie the remainder upon dividing the counter by three). The remainder of the calculation, +IF(MOD(L$4,List_Depth)=0,List_Depth,0), simply forces a 0 to 3 instead, so that the Selector gives the values 1, 2 and 3 alternately. Year No. (row 8): simply notes which year the column is reporting using the formula: =ROUNDUP(L$4/List_Depth,0), ie the year increases the period after the counter is a multiple of three (in this example). Using List_Depth as a variable means that this idea can be easily extended to summarise other data such as reforecasts, % differences etc (ie have different periodicities). In my example, row 13 requires a very simple formula to generate the required outputs: =OFFSET(BC_Sales_Summary,L$7,L$8). BC_Sales_Summary is a range name (see October 2011s article) where BC stands for base cell and in my example would be cell K28 in the interim calculation illustration. The reference would then be offset by Selector number of rows (e.g. if the value of Selector were 3 it would reference the Variance row) and by Year No. number of columns (e.g. if the value of Year No. were 2 it would refer to the 2013 data). For example, cell Q13 equals OFFSET(BC_Sales_Summary,3,2), which would refer to the 2013 Variance figure USD840. Easy! This idea can be extended very simply using range names for greater transparency. Please see the attached Excel file (239KB) for further details. Posted in All skills, Modelling | Leave a reply

Automated file names


Posted on January 8, 2013 Query For version control purposes, I want to display the current filename of my workbook within one or more worksheets. Is there a way to do this short of typing it in manually? Advice Where theres a will theres a way, and I use the following formula: =IF(ISERROR(OR(FIND([",CELL("filename",A1)),FIND("],CELL(filename,A1)))),",MID(CELL(filename,A1),FIND([",CELL("filename",A1))+1,FIND("],CELL(filename,A1))FIND([",CELL("filename",A1))-1)) Obvious, yes? I have a rule of thumb when writing a formula. Quite literally. In general, for formulae to be transparent, they should appear no longer than the length of your thumb in the formula bar. Of course, there are exceptions to many great rules, and this is one of them. The above formula needs explanation. Padded CELL This function returns information about the formatting, location, or contents of the upper left cell in a reference. In our example, we will be using cell A1 as our reference in the active worksheet, but this selection is entirely arbitrary as long as a selection is made.

Info_Type "address" "col" "color" "contents" "filename"

Returns Reference of the first cell in reference, as text. Column number of the cell in reference. 1 if the cell is formatted in colour for negative values; otherwise returns 0 (zero). Value of the upper left cell in reference; not a formula. Filename (including full path) of the file that contains reference, as text. Returns empty text ("") if the worksheet that contains reference has not yet been saved.

"format"

Text value corresponding to the number format of the cell. The text values for the various formats are shown in the following table. Returns "-" at the end of the text value if the cell is formatted in colour for negative values.

www.cimaapps.com/spreadsheetskills/?cat=5

16/18

1/11/13

All skills | CIMA Spreadsheet Skills


Returns "()" at the end of the text value if the cell is formatted with parentheses for positive or all values. "parentheses" "prefix" 1 if the cell is formatted with parentheses for positive or all values; otherwise returns 0. Text value corresponding to the "label prefix" of the cell. Returns single quotation mark (') if the cell contains left-aligned text, double quotation mark (") if the cell contains right-aligned text, caret (^) if the cell contains centred text, backslash (\) if the cell contains fill-aligned text, and empty text ("") if the cell contains anything else. "protect" "row" "type" 0 if the cell is not locked, and 1 if the cell is locked. Row number of the cell in reference. Text value corresponding to the type of data in the cell. Returns "b" for blank if the cell is empty, "l" for label if the cell contains a text constant, and "v" for value if the cell contains anything else. "width" Column width of the cell rounded off to an integer. Each unit of column width is equal to the width of one character in the default font size.

We therefore use the syntax =CELL(filename,A1). An example of a returned filename might be: C:\Documents and Settings\Liam\My Documents\Spreadsheet Doctor\Doctor 30 - Automated Filename\[Example Workbook.xls]Sheet1 This is not what we require. All we want is the actual filename, in this case Example Workbook.xls. So we need to extract the filename from this worksheet directory path. This will be a three step process. Step one: FINDing the beginning and the end The directory path will vary for each file, so we need a foolproof method of finding the beginning and the end of the workbook name. Fortunately, Excel helps us here. [ and ] denote the beginning and the end of the workbook name. The example returned filename above is 122 characters long. If we can find the position of the [ and ] we will be on our way. FIND(find_text,within_text,start_num) is the function we need, where: find_text is the text you want to find within_text is the text containing the text you want to find start_num (which is optional) specifies the character at which to start the search. The first character in within_text is character number 1. If you omit start_num, it is assumed to be 1. In our example, =FIND([",CELL("filename",A1)) returns the value 95 and the formula =FIND("],CELL(filename,A1)) returns the value 116. So, for this illustration, if we can get Excel to return the character string in positions 96 to 115 inclusive (between the square brackets) we will have our workbook name. Step two: LEFT a bit, RIGHT a bit, aim for the MID section There are various functions in Excel that will return part of a character string: LEFT(text,num_characters) returns the first few characters of a string depending upon the number specified (num_characters). This is not useful here as we do not want the first few characters of our text string RIGHT(text,num_characters) returns the last few characters of a string depending upon the number specified (num_characters). This is not useful here either as we do not want the last few characters of our text string MID(text,start_num,num_characters) returns a specific number of characters from a text string, starting at the position specified, based on the number of characters chosen. Therefore, we should use the MID function here. In hard code form, our formula would be: =MID(CELL(filename,A1),96,20) where: 96 = position one character to the right of [ (95 + 1) 20, which is the length of the filename string, being the position of ] less the position of [ less 1, i.e. 116 - 95 - 1 = 20. This gives us our filename Example Workbook.xls. The problem is we dont want hard code: a flexible formula is required. Using the concepts explained above, we derive:

www.cimaapps.com/spreadsheetskills/?cat=5

17/18

1/11/13

All skills | CIMA Spreadsheet Skills


=MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,FIND("],CELL(filename,A1))-FIND([",CELL("filename",A1))-1) And so we are done. Except we arent, quite. Step three: error trapping A good modeller will always make sure that a formula will work in all foreseeable circumstances. The above formula will only work if the file has been named and saved. Otherwise, CELL("filename",A1) will return empty text (), which will cause the embedded FIND formulae to return #VALUE! errors, so the overall formula will also return the #VALUE! error. We need an error trap a check that ensures that if the file has not been saved we just get empty text () returned. To do this, we can use the following formula: =IF(ISERROR(OR(FIND("[",CELL("filename",A1)),FIND("],CELL(filename,A1)))),",1) ISERROR(expression) gives a value of TRUE if the expression is evaluated as an error, otherwise it is FALSE. In our equation above, if the file has not been saved, this formula will return the empty text (), otherwise it will return our dummy value of 1. Substituting our derived formula above for the 1 gives us the final formula: =IF(ISERROR(OR(FIND([",CELL("filename",A1)),FIND("],CELL(filename,A1)))),",MID(CELL(filename,A1),FIND([",CELL("filename",A1))+1,FIND("],CELL(filename,A1))FIND([,CELL(filename,A1))-1)) It is not pretty, short or transparent, but it is flexible and robust. Final note The formula above is intended to be copied as it is straight into an Excel worksheet by pasting it directly into the Excel formula bar and pressing ENTER. In certain situations it will not work due to your copying method, font, or the setup of the ASCII characters. In this instance, try retyping all of the inverted commas ( and ) in the formulae first. If this doesnt work you will have to retype it. Cest la vie. Posted in All skills, Useful formulae | Leave a reply

www.cimaapps.com/spreadsheetskills/?cat=5

18/18

You might also like