Save content
Have you found this content useful? Use the button above to save it to your profile.
AIA

Tutorial: Analyse Sales and Margins with pivot tables [Excel 2000 & 2003]

by
20th Jul 2006
Save content
Have you found this content useful? Use the button above to save it to your profile.

This article updates IT Zone consultant editor David Carter's hugely popular pivot table tutorial, which applies Excel's powerful multidimensional analysis tool to one of the most common business reporting activities - sales analysis.

In this tutorial you will learn how to use pivot tables to analyse your company's sales. You will also use Excel's 'Import Wizard' to load into Excel a data file that was exported from a third party accounts package.

The accompanying data file SALANAL.TXT contains 4,188 sales invoice line detail records taken directly from an accounts package such as Navision, Pegasus Opera, SunSystems, and so on.

The data has been exported from the accounts package as a Text file, which Excel can then import via the Import Wizard. Files in Text format are sometimes also called CDF (Comma Delimited Files), or CSV (Comma Separated Values) or ASCII files.

Package suppliers now recognise that it is essential to include facilities to export data into Excel. Hopefully, you will be able to get your own sales data into Excel and analyse it with pivot tables as we do here. Pivot tables allow you to analyse the sales invoices in pretty well any way you want - sales by customer, sales by product group, sales by period, sales by sales rep and so on.

This tutorial should take you about 60 minutes to work through. If possible, it is a good idea for two people to do it together, one reading the instructions, the other operating the keyboard. You can download a Word version of this tutorial and if you have any difficulties getting the download instructions to work, there is an additional StartUp.Doc file with further information.

You will make extensive use of both left and right mouse buttons. 'Right click' means click the right mouse button. When you see 'click' on its own, click the left mouse button.

The tutorial is designed to be used with Excel 2003 and Excel 2000. There is an earlier version for use with Excel 5, Excel 95 and Excel 97.

More Pivot Table tutorials are available via in the Expert Guides section of IT Zone.

Importing the text file into Excel
Start up Excel. Import the SALANAL.TXT file into Excel as follows:

1. File-Open. Open the folder that contains SALANAL.TXT. You can't see SALANAL.TXT. The pull-down menu at the bottom reads: Files of Type. Change it from Microsoft Excel Workbook to Text Files

2. SALANAL now appears. Open it. The Text Import Wizard, Step 1 of 3 appears. Excel should have determined that the Data Type is Delimited, not Fixed Width.

3. If it has, click Next. The Text Import Wizard - Step 2 of 3 appears. There should be vertical lines between the columns (Excel identifies the tab marks as delimiters).
In addition, you can see field names at the head of each column ' TRANSN, INVNO, DATE, etc.

4. Click Next. Step 3 of 3 appears.
The TRANSN column is highlighted. At the head of the column is the format which Excel assumes it will be in when it is imported ' the GENERAL format. Excel assumes GENERAL for all fields.

At top right are the possible Column data formats: General, Text, Date, Skip (ie do not import). General format is OK for all your fields except DATE. You will need to change the date format.

In the Column Data Format box at top right the Date option should have the default value DMY against it. This means that Excel is expecting that any Date fields it finds in the text file will be in Day/Month/ Year format, which is the UK standard. If DMY is not the default offered, select DMY from the list so that it is.

5. Click on the General heading of the third column, DATE. The column is highlighted. At the top right click on: Date. The heading of the DATE column should now read DMY.

6. Click on Finish. Wait a moment. The file is imported into Excel.
Note: If your default date format was MDY rather than DMY, this means that your PC is set to express dates in month/day/yearUS format. If you are a UK user you need to change this now to UK day/month/year format. Cancel the Import wizard and come out of Excel. Close down all other programs, because you will have to reboot your machine. Then select: Start Settings Control Panel-Regional Settings. Change from English (United States) to English (United Kingdom) or English (British). Reboot the PC as instructed. Start the tutorial again. This time the Import wizard should offer DMY as default.

Tidying up the file
A Text file imported from another system will have lost most of its formatting. Therefore it first needs to be tidied up:

1. Highlight the first row of the spreadsheet by clicking on the 1 to its left. Then click B on the toolbar to make the column headings Bold.

2. Click on the top left-hand grey brick above the 1 and left of the A. The whole worksheet is highlighted.

3. Double-click between column headings A and B. All the columns are widened to their best fit.

4. Highlight Row 2 by clicking on 2 at the left. Then select: Window-Freeze panes

5. Now copy the file into a suitable directory and convert it to Excel format, as follows: File-Save As. Leave the file name as SALANAL but below the filename change Save as Type from Text (Tab delimited) to Microsoft Excel Workbook. Save.

Contents of the SALANAL database
The database is a set of records derived from the sales invoice detail file within the accounts package. Each record contains the following fields:
TRANSN = Transaction Type (ie Invoice, or Credit Note in this case)
INVNO = Invoice or Credit Note number
DATE = Invoice or Credit Note Date
ACCNO = Customer Account Code
CUSTNAME
PARTNO
DESCRIPTION
MANUFR = Manufacturer (this is old data, and quite a few of these are now defunct)
PRODGROUP = Product Group
QTY = Quantity Invoiced
S.P. = Item Selling Price
NET = Line Net Value (ie Qty x S.P.)
C.P. = Item Cost Price
COST = Line Cost (ie Qty x CP)
MRGN = Line Margin (ie NET ' COST)
SALES EXEC = our Sales Representative

So, taking the first two lines as an example, on 4th, April 2004 we issued sales invoice number SIN001649 to customer no. R001, Rolls Royce Ltd, for two products ' HP51625A Colour Print Cartridge, quantity 2, at £18 each, and a US Robotics Sportster 28.8 External modem, quantity 1, at £228 each.

Moving around the file
Scroll down through the first 100 or so records to see the sort of data the file contains. Then:

Go to the bottom of the file: (tip: hold down the right hand Ctrl key with your right thumb, then press Down arrow)
There are 4,188 rows (i.e. 4,188 sales invoice detail records)

Go to the bottom of column L, the NET column.
Click onto the L at the top of column L. At the bottom of the screen it says 'Sum = 5442458

Make a note of this number. Click to remove the highlighting from column L.
Return to the top of the file. (keyboard shortcut = hold down Ctrl, then press 'Home' key.)

Generating a pivot table
The cell pointer should be on A2 (or anywhere within the data will do). We'll build up the pivot table step by step.

1. From the main menu at the top of the screen, select :
Data-Pivot Table and Chart Report. The Pivot Table Wizard, Step 1 of 3 screen appears.

2. Click on Next. Step 2 of 3 appears The Range box should say: $A$1:$P$4188.
Earlier versions of Excel sometimes didn't pick up the range automatically. If the Range box is blank or says 'Database', type in $A$1:$P$4188 by hand.

3. Click on Next. Step 3 of 3: Click on Layout at bottom left. The COLUMN-ROW-DATA box appears. To the right are all the column headings of your spreadsheet. Drag and drop PRODGROUP into the ROW area and NET into the DATA area
When dropped into the DATA area, NET should now say 'Sum of NET'. If it says 'Count of NET', double click on Count of NET. A box appears. Change 'Count' to 'Sum'].

4. Now click on OK then Finish.
A list of Product Groups appears with a total beside each one. At the bottom of the sheet is the total 5442458. From the 4,188 records in SALANAL, Excel has generated a pivot table summarising total Net Sales by Product Group.

Look at the bottom left of your screen. To create the pivot table, Excel has generated a new worksheet to the left of SALANAL. This sheet is probably named Sheet1. Click back onto the SALANAL worksheet. The original sales invoice database is still there.

5. Now right click back onto Sheet1 with the pivot table. Rename this worksheet PIVOT.

Formatting the numbers in a pivot table
The sales figures would be easier to read if the thousands were separated by commas. Therefore:

1. Click on any of the numbers in column B. Then right click the mouse. A menu appears, with 'Format Cells' at the top.
If you are using Excel 2003, clear the screen with Hide Pivot Table Toolbar and Hide Field List.

2. Then select: Field Settings.
The Pivot Table Field dialogue box appears. From the options on the right, select: Number.

3. The 'Format Cells' box appears. From the 'Category' list, select: Number.

4. Then: Decimal Places = 0-1000 separator?, tick for YES -1234 in red OK OK
In the pivot table commas now separate the thousands.

Sorting the pivot table
You would like to rank the product groups to show the best sellers first. To do this:

1. Click anywhere in the Total column, eg on cell B10

2. Click on the ZA icon. The Product groups are sorted in Descending order, with PC's at the top
If you don't have the ZA icon, use the AZ icon instead and sort ascending.

3. Now move your mouse pointer around the top of cell A4 PRODGROUP until it turns into a thick black vertical down arrow. Then click the mouse. The column is highlighted.
If you can't get the black down arrow, it may be because selection is switched off. Right click for menu-Select-Enable Selection. Now try again.

4. Click on the AZ icon. The product groups are sorted back into alphabetical order, ascending.

Analysing sales by customer
Having seen sales by Product Group, you would now like to analyse them by customer.

1. Right click anywhere within the pivot table. The menu appears.

2. From the menu, choose: Wizard-Layout. The COLUMN-ROW-DATA box re-appears.
[NB: Excel 2003 = Pivot Table Wizard]

3. Drag and drop PRODGROUP anywhere outside the ROW area.

4. Drop ACCNO into the ROW area.

5. Then drop CUSTNAME below ACCNO in the ROW area. Then: OK-Finish.
The pivot table now displays sales by Customer account number and name. But the screen is not very clear as the ACCNO is totalling. These totals need to be removed:

6. Right click on the grey ACCNO field button in cell A4. The menu appears

7. Select: Field Settings.
In the Subtotals area on the left, change from Automatic to None. OK
That looks better. Note that the total is again 5,442,458. This time the sales are broken down by customer.

Summarise sales by month
The sales invoices were dated from April to September. We will summarise them by month:

1. Right click within the pivot table. The menu appears. Select: P/T Wizard-Layout. The COLUMN-ROW-DATA box re-appears.

2. Drag and drop DATE into the COLUMN area. OK. Finish. The pivot table is recalculated.

3. Across the top there is now a series of dates. They need to be grouped by month. To do this, right click on the grey DATE field button in cell C3. The menu appears.

4. Select: Group & Outline-Group [In Excel 2003 Group and Show Detail Group]. The Grouping Dialogue Box should now appear.
If it doesn't, but you get the message 'Cannot Group That Selection', see the paragraph below.

5. Select Months and Years (at the bottom of the list under Quarters). OK. The pivot table now displays the Net sales by month.

'Cannot Group This Selection'
You should not get this error message during the tutorial. However, if you ever do, it may help to know that while it is invaluable, the Group command can be a bit temperamental. I get more trouble trying to group date fields than all other problems put together. And if it does fail, the only feedback you get is 'Cannot Group This Selection'. There are two likely sources of error. First, your default date format in Windows is set to US month/day/year format, whereas the date fields in your imported data were expressed in UK day/month/year format. To check this, take a closer look at the way your dates are currently formatted in Excel. If you are a UK user and they are US with the month first, you need to reset your Regional Settings in Control Panel, as described in the first section. Then restart the tutorial over again.

The second possibility is that one or more date fields within your data are either blank or not formatted correctly as dates. First thing to do is to go into the SALANAL worksheet, click anywhere on the DATE column BUT NOT THE COLUMN HEADING ITSELF, then click the AZ icon. This sorts the database into date order. Look at the first and the last dates in the worksheet as this is where faulty dates will appear. Correct any errors, then Refresh Data. Second, check that the Range is not looking at any blank rows, which will contain blank date fields. Do this via Wizard-Back, which should show you the Range $A$1:$P$4188. If it says $A$1:$P$4189, then you need to change it to $P$4188.

Even when you've corrected all the errors, when you Refresh Data you may still get the 'Cannot Group This Selection' message. In this case delete the entire pivot table and build it again from scratch: this time it should work. Finally, sometimes a Date field will not Group when put in the ROW area, but will if put it in the COLUMN area In this case, Group them first in COLUNM, then go into the wizard and move Years/Date out of COLUMN and into ROW. You will find that the Grouping stays OK

Shade the column headings
We will tidy up the column headings with some shading.

1. Move the mouse pointer over DATE in D3 until it turns into a thick down arrow, then click. The column headings 'Apr' to 'Sep' are highlighted.

2. To add shading, click on the yellow 'Fill Color' icon in the bottom row of icons, second from right (the one that looks like it's pouring a can of paint).

3. Centre the months by clicking the Centre icon. Also click the B icon for Bold print.

4. Now click anywhere to remove the highlighting. The monthly headings are all shaded yellow.

Analysing sales by manufacturer
So far we have analysed sales by product group and sales by customer. Now we will analyse them by manufacturer, then see which manufacturer's products are selling the best.

1. Right click within the pivot table for menu. Select: P/T Wizard-Layout. The COLUMN-ROW-DATA box re-appears.

2. Remove ACCNO and CUSTNAME by dropping them anywhere outside the table.

3. Drag and drop MANUFR into the ROW area. In addition, drop PRODGROUP onto the PAGE area. OK. Finish
The pivot table is recalculated, showing sales by manufacturer. Again, the total is £5,442,458.

The list of manufacturers should be in alphabetical order, starting with 3COM. But sometimes DEC appears first ' I've no idea why. If it does, sort the manufacturers alphabetically as follows:

Move the mouse pointer over MANUFR in A5 until it turns into a thick down arrow, then click. The column is highlighted. Click on the AZ icon. The column is sorted and DEC goes to its proper position.

Adding a further dimension with page fields
So far the data is presented in two dimensions, by rows and by columns. However, you can add a third dimension of analysis by using the PAGE field.

For example, we might wish to see which brand of PC is selling the best. Therefore:

1. PRODGROUP is the Page field in cell A1. Click on the down arrow in the right of cell B1.
You see a list of the product groups - (All), COMMS, INTERNET, MEMORY, MONITORS etc.

2. Highlight PCs OK. The pivot table now shows only those manufacturers who sell PC's. Total PC sales were £2,813,885. The best seller was DEC, with sales of £1,026,424.

3. Click on the B1 down arrow again and now look at the sales for PRINTERS. The total value of sales by manufacturer is shown (£243,132). But which models sold best?

4. To find out, right click for menu: P/T Wizard-Layout.

5. Drag PARTNO and drop it under MANUFR in the ROW area.

6. Drag DESCRIPTION and drop it under PARTNO in the ROW area

7. In the ROW area, double click on PARTNO. The Pivot Table Field box appears

8. Change Subtotals from Automatic to None. OK. OK Finish
The pivot table is redisplayed, but this time shows sales of the individual models of printer.

Hiding the detail
The Hide Detail and Show Detail commands will expand and collapse the pivot table. So:

1. Right click on A4, MANUFR. From the menu select: Group and Outline-Hide Detail. The pivot table is summarised back to top level with one line per manufacturer.

2. To see more detail for EPSON, Double left click on EPSON in cell A6. Excel expands EPSON to show the individual products.

3. Double left click anywhere in the gap below EPSON, say cell A8. You go back to one summary line.
You can see the detail of any manufacturer, just by double clicking on them. Try IBM. IBM is expanded. Now double click in the gap below IBM. You go back to summary level.

Shading subtotal lines
We want to make the sub-totals for Canon, Epson etc stand out by shading them.

1. Move the mouse pointer to the grey 15 brick left of cell A15, 'CANON Total'. Move it gradually to the right until it turns into a thick horizontal black arrow. Then left click the mouse. All the sub-total lines are highlighted.
Note: if the black arrow stays within the 15 box, only Row 15 is highlighted. But if the arrow is partly over cell A15 as well, ALL the sub-total rows are highlighted.

2. We'll use the yellow Fill Color icon again (the one that looks like it's pouring a can of paint). However, this time click on the down arrow to the right of the icon, and select a colour from the palette. Personally, I like light blue or light green in the bottom row.

Sales and gross margin by sales executive
Having analysed the company's sales by product group, by customer, by manufacturer and by product, we will now analyse sales by salesperson.

1. Right click for menu: P/T Wizard-Layout. COLUMN-ROW-DATA box re-appears.

2. Drop MANUFR, PARTNO and DESCRIPTION out of the ROW area. And drop PRODGROUP out of the PAGE area.

3. Now drop SALES EXEC into the ROW area. OK Finish
The pivot table is recalculated to show sales by sales executive. Total sales are still £5,442,458. Top salesmen over the 6 months were Eddie Mars (£1,643,489) and Bernie Ohls (£1,116,160).

But suppose you pay your sales force on the basis of gross margin earned, not turnover:

1. Right click for menu: P/T Wizard-Layout. COLUMN-ROW-DATA box re-appears.

2. Drop MRGN below 'Sum of NET' in the DATA area, so you get 'Sum of MRGN' OK. Finish.
Now the pivot table shows the Margin each salesman has earned, underneath their Net sales.

We'll tidy the MRGN lines up a bit. Firstly, put commas between the thousands as follows:

1. Move the pointer to the left of Sum of MRGN until you get a thick black right arrow, then click

2. Right click for menu. Field Settings. From the right hand list of options, select: Number

3. Then: Number Decimal Places = 0-1000 separator, YES. -1234 in red. OK. OK.
The MRGN lines now include commas separating the thousands.

4. The Sum of MRGN lines should still be highlighted. Now:
Click the down arrow on the Fill Color icon (the yellow paint can). A palette of colours appears.

5. From the palette, select Tan (bottom row, second from left).

6. Click anywhere to remove the highlighting. The Margin lines are all shaded light brown.

Printing the sales report
We will print out this pivot table showing monthly sales and margin by sales executive.
You don't have to print this report. If you wish, you can skip this and go on to the next section.

1. First, click the Print Preview icon to see the report on screen.
This report would look better if printed in Landscape. Therefore select::

2. Setup-Page-Landscape-OK. Then select:

3. Setup-Margins: at bottom, tick the Horizontally and Vertically boxes OK. Then, select:

4. Setup-Sheet: Check the Gridlines box. OK. Then select:

5. Setup-Header/Footer. Then click on: Custom Header. Type in the following:
Left Section: Type: Printed: then click on the 8/7 icon. &[Date] appears
Right section: Type: Page: Then click the # icon. Type: of - Click on the ++ icon.
Center section: Type in capitals SALES AND MARGINS BY SALES EXECUTIVE

6. Highlight this text with the mouse.

7. Click on the A icon. The Font box appears.

8. Select Bold and 10. OK. OK. OK.

9. Press Print to print the report.

Displaying 'NET' and 'MRGN' in columns
The sales by Sales Exec screen displays the NET and MRGN values underneath each other. You would prefer to see them side by side:

1. Right click for menu: P/T Wizard-Layout.

2. Move Years and DATE into the PAGE area. OK. Finish. The row of months disappears.

3. Wave the mouse over Sum of Margin for thick black right arrow. Click to highlight all rows.

4. We'll remove the colouring. Click on the down arrow in the Fill Color icon. The colour palette appears.

5. Click the No Fill box. The brown colouring disappears.

6. Now click the left hand mouse button on the grey DATA field button in cell B4 and hold it down. Now drag it down a few millimetres until an icon with a slab of blue to the left appears.

7. Keeping your eye on the slab of blue, slowly drag the brick over to the Total box in cell C4. When the slab of blue changes to horizontal, release the mouse key.
The pivot table is reformatted, with Sum of NET and Sum of MRGN side by side.

Using formulas to calculate gross margin percentage rate
Margin is obviously important, but you suspect some of your salesmen have been buying business by discounting the list price. So you want to see the gross margin percentage your salesmen are making on sales.

We will use the Formulas option to calculate gross margin percentage (ie Margin divided by Net Sales value).

1. Right click on the pivot table for menu. Select: Formulas-Calculated Field
In Excel 2003 the Formulas option is rather hidden away. From the menu, select Pivot Table Toolbar ' click on Pivot Table at the left-click the down arrows to display the complete menu. Select: Formulas-Calculated field.

2. The Insert Calculated Field box appears.

3. In the Name box, replace 'Field1' with 'MGN%'

4. In the Formula box, click to the left of the 0. Delete the 0 Then:

5. In the list of Fields, find MRGN and highlight it. Then click on Insert Field. MRGN appears in the Formula box

6. To the right of MRGN, add a right slash (/) , meaning 'divide by'.

7. Go back into the list of fields. Find NET and highlight it. Insert Field
The Formula box should now display the formula =MRGN/NET

8. Click on Add, then OK A fourth column appears in the pivot table, entitled 'Sum of MGN%'. It needs to be reformatted as a percentage. Also, the 'Sum of MGN%' title is making it too wide.

9. Right click anywhere in the new column. From the menu, select: Field Settings.

9. In the Name box at the top, click to the right of the f in 'Sum of'. Then use the big Left Arrow key to delete
everything to the left . (Leave one blank space before MGN%, otherwise Excel gets confused)

10. Also select: Number-Percentage-Decimal places = 0. OK. OK.
Interesting. While Eddie Mars and Bernie Ohls have generated the biggest margin in absolute terms, Vivian Regan and Jane Seymour are earning the highest percentage return on sales. And what on earth is Harry Jones doing at only 25%?

We need to 'slice and dice' to find out what's happening. Maybe the answer lies in the different mix of products they are selling. So: Right click for menu: P/T Wizard-Layout.

1. Move SALESEXEC into the PAGE area. Put PRODGROUP in the ROW area. OK. Finish.
The pivot table is recalculated, showing the margin earned by Product Group.

2. Now, next to SALES EXEC, click on the down arrow in column B. Select: Harry Jones.
Most of Harry's sales were PCs. That's hardware, with a margin percentage of only 33%.

3. Now from the list choose Vivian Regan. Over half of her sales (£136,559) were TRAINING, which is services. They generated 97% margin!

Drilling down on a value to see the underlying transactions
An invaluable feature of pivot tables is the ability, if you are doubtful about a value, to drill-down on that value and see the individual transactions that make it up.

So in this case, the margin of 136,559 on TRAINING needs to be checked.

1. Double click on the: 136,559. A new worksheet is generated, listing all the transactions..

2. Click anywhere in the data to remove the highlighting.

3. Scroll to the right to see the NET and COST values for each line in columns L and N.
In many cases the COST is zero, resulting in 100% gross margin. This explains the 97% average.

4. Finally, right click back onto the PIVOT worksheet.
OK. It's time to take break. Save your work via: File-Save. Then relax.

Final food for thought
This is your first hint of the fact that, when data is exported from an accounts package, it will invariably contain errors in the form of wrong values, miscodings, blank records, etc.
Before anything, you will first have to tidy the data up.

Cost prices are a particular problem. Sales admin departments, who process the sales orders and invoices, are usually not bothered about them. Selling prices are obviously important, since customers will complain if they are wrong. But who cares about accurate cost prices?
In addition, when services are supplied as opposed to products, it is often difficult to work out what exactly is the true cost?

While sales admin or marketing personnel can be trained to use pivot tables to report sales by quantity or value, they should NOT be allowed to report on margins and profitability. This should only be done by a trained accountant, who is able to appreciate the potential pitfalls.

David Carter

Replies (2)

Please login or register to join the discussion.

avatar
By David Carter
18th Nov 2004 23:17

At last
That's been puzzling me for 10 years. Thanks.

Thanks (0)
avatar
By mehmoodsha
31st Oct 2006 17:14

Great tutorial
A very good article.

Thanks (0)