to save your powerpivot workbook - sql safety | sql ... · web viewin the powerpivot window, on the...

29
Introduction To PowerPivot To create a connection to an Access database 1. Navigate to the location on your computer where you downloaded the samples and double-click Stores. You will use the stores data in a later lesson. 2. In the Excel window, on the PowerPivot tab, click PowerPivot Window. 3. In the PowerPivot window, on the Home tab, click From Database, and then click From Access. The Table Import Wizard launches and guides you through setting up a connection to a data source. 4. In the Friendly connection name box, type ContosoDB from Access. 5. To the right of the Database name box, click Browse. Navigate to the location where you downloaded the sample files, select ContosoSales, click Open, and then click Next to continue. 6. Verify that Select from a list of tables and views to choose the data to import is selected, and then click Next to display a list of all the source tables within the database. 7. Select the check box for the following tables: DimChannel, DimDate, DimProduct, DimProductSubcategory, and FactSales. (Do not yet close the Table Import Wizard.) Now that you have connected to the database and selected the tables to import, go to the next section below, Filter the Table Data prior to Importing . Filter the Table Data prior to Importing The FactSales and DimProduct tables that you are importing from the Access database contain a subset of the data from the original SQL Server Contoso database: sales and products from two categories (games and home appliances) are not included. You will apply a filter to one of the other tables before importing it, so that you eliminate the same categories. You will also filter out some of the columns from the DimProduct table. To filter the table data prior to importing 1

Upload: trannhan

Post on 29-Apr-2018

221 views

Category:

Documents


1 download

TRANSCRIPT

Introduction To PowerPivot

To create a connection to an Access database

1. Navigate to the location on your computer where you downloaded the samples and double-click Stores. You will use the stores data in a later lesson.

2. In the Excel window, on the PowerPivot tab, click PowerPivot Window.3. In the PowerPivot window, on the Home tab, click From Database, and then click From

Access. The Table Import Wizard launches and guides you through setting up a connection to a data source.

4. In the Friendly connection name box, type ContosoDB from Access.5. To the right of the Database name box, click Browse. Navigate to the location where you

downloaded the sample files, select ContosoSales, click Open, and then click Next to continue.

6. Verify that Select from a list of tables and views to choose the data to import is selected, and then click Next to display a list of all the source tables within the database.

7. Select the check box for the following tables: DimChannel, DimDate, DimProduct, DimProductSubcategory, and FactSales. (Do not yet close the Table Import Wizard.)

Now that you have connected to the database and selected the tables to import, go to the next section below, Filter the Table Data prior to Importing.

Filter the Table Data prior to Importing

The FactSales and DimProduct tables that you are importing from the Access database contain a subset of the data from the original SQL Server Contoso database: sales and products from two categories (games and home appliances) are not included. You will apply a filter to one of the other tables before importing it, so that you eliminate the same categories. You will also filter out some of the columns from the DimProduct table.

To filter the table data prior to importing

1. Select the row for the DimProduct table, and then click Preview & Filter. The Preview Selected Table dialog box opens with all the columns in the DimProduct table displayed.

2. Scroll to the right, and clear the checkboxes at the top of the columns for all the columns, from ClassID through StockTypeName (a total of 15 columns; stop before UnitCost), and then click OK.

Notice that the words Applied filters appear in the Filter Details column in the DimProduct row. If you click on that link, you will see a textual description of the filters that you just applied.

3. Now select the row for DimProductSubcategory, and then click Preview & Filter.4. Since you are interested in only some of the products, you will apply a filter so that you

import only the data for these categories.

1

Introduction To PowerPivot

Scroll to the right. At the top of the ProductCategoryKey column, click the arrow on the right side of the cell, scroll down, deselect 7 and 8, and then click OK. Categories 7 and 8 include games and home appliances, and you do not want to include those in your analysis. The arrow in that cell changes to a filter icon.

5. At the top of the ProductSubcategoryDescription column, clear the checkbox on the left side of the cell. Since the descriptions are almost identical to the names, you do not need to import both columns, and eliminating unnecessary columns makes your workbook smaller and easier to navigate. Click OK.

Import the Selected Table and Column Data

Finally, import the selected data. The wizard imports the table relationships along with the table data. For more information about relationships, see Relationships Between Tables.

To import the selected table and column data

1. Review your selections. If everything looks okay, click Finish.

While it imports the data, the wizard displays how many rows have been fetched. When all the data has been imported, a message appears that indicates success. Notice that you imported more than 2 million rows from the FactSales table alone.

2. Click Close.

The wizard closes, and then the data appears in the PowerPivot window. Each table has been added as a new tab in the PowerPivot window. If the data changes at the source, you can keep the data imported into the PowerPivot window up-to-date by using data refresh. For more information, see Different Ways to Update Data in PowerPivot.

To create a connection to an Access database

1. In the PowerPivot window, on the Home tab, click From Database, and then click From Access. The Table Import Wizard appears and guides you through setting up a connection to a data source.

2. In the Friendly connection name box, type Product Category Access DB.3. To the right of the Database name box, click Browse. Navigate to the location where

you downloaded the sample files, select ProductCategories, and then click Open.4. Click Next.

Use a Query to Select the Data to Import

2

Introduction To PowerPivot

The procedure for using the Table Import Wizard to import by selecting from a list of tables was described in the previous lesson in this tutorial. So instead of duplicating those steps, you will use a custom query to import this set of Access data.

The Table Import wizard guides you through the steps. You can either import a query, copy and paste the text of an existing query, or write a new query by using the PowerPivot graphical query builder. In this lesson, you will import a query that you received from the IT department.

To use the query designer tool to select the data to import

1. Select the Write a query that will specify the data to import option, and then click Next.2. In the Friendly Query Name box, type Product Category Query.3. Click Design to open the Query Builder dialog box.4. Click Import, and then navigate to the location on your computer where you saved the

samples. 5. If you do not see the file listed, click the file down arrow, and then select All files (*.*).6. Select SQLQuery, and then click Open.

The SQL statement appears in the window. This query selects all data from the ProductCategory table except GAMES and TOYS and HOME APPLIANCES.

7. Click OK, Validate, and then Finish. A summary of the columns you are importing appears.

8. When the import is finished, click Close.

The data is displayed as a new table named Query in your PowerPivot workbook. You can keep this data current by refreshing. If the contents of the Access database change, refreshing keeps your PowerPivot data up-to-date. For more information, see Different Ways to Update Data in PowerPivot.

9. Rename the new table by right-clicking the Query tab and selecting Rename. Type ProductCategory and then click Enter. If a message dialog box opens, click OK.

Copy and Paste from an External Excel Worksheet

The Sales department has an Excel spreadsheet that contains data about the location of areas where Contoso is currently selling products. You will copy the data that you need from this worksheet, and paste it into your PowerPivot workbook.

To copy and paste from an external Excel worksheet

1. Navigate to the location on your computer where you downloaded the samples, and then double-click Geography. A new Excel worksheet opens, and you are no longer in the PowerPivot window.

2. Highlight and copy cells A1 through J675 (including the row of column headers).

3

Introduction To PowerPivot

Note Be sure to select only this range of cells and not whole rows and columns. Selecting whole rows and columns imports empty cells, which might affect your ability to create relationships with this data.

3. Back in your PowerPivot window, on the Home tab, click Paste. The Paste Preview dialog box displays the new table that will be created.

4. Type Geography in the Table Name text box. 5. Make sure that the table data is correct, make sure Use first row as column headers is

selected, and then click OK. The new table is created in the PowerPivot window.

Create a Linked Table

In the previous task (Add Data by Using Copy and Paste (Tutorial)) the Geography table is static because after you pasted the data, it is not automatically updated. Linked tables, on the other hand, automatically reflect changes that were made to the source. Linked tables must reference Excel data found in a separate Excel window within the same PowerPivot workbook.

To create a linked table

1. In the Excel window, point to any of the cells in the Stores worksheet and format it as a table (CTRL+T). Make sure My table has headers is selected. Click OK.

2. The new table that will appear in the PowerPivot window always has the same name as the table in Excel. Therefore, you should give the Excel table a meaningful name before you create the linked table in PowerPivot. By default, Excel automatically generates names for tables (Table1, Table2, etc) but you can easily rename tables by using the Excel interface.

1. While you are still in the Excel window, click the Design tab. 2. In the Properties area, under Table Name: type Stores.3. In the Excel window, on the PowerPivot tab, click Create Linked Table. The

PowerPivot window opens, and a new table has been created. Notice the link icon on the tab.

4. In the PowerPivot window, on the Linked Table tab, click Go to Excel Table to return to the source table in the Excel window. Change the value in cell C2 from 35 to 37.

5. Return to the PowerPivot window. The corresponding row has now been updated to the new value as well.

To save your PowerPivot workbook

1. In the Excel window, click the File tab.2. Click Save As. The Save As dialog box opens.

You will save the workbook as the default file type of Excel Workbook (*.xlsx). For a list of supported file types, see Learn About PowerPivot Capabilities.

4

Introduction To PowerPivot

3. In the File name text box, type PowerPivotTutorialSample, and then click Save.

Why Create Relationships?

In order to perform any meaningful analysis, your data sources must have relationships between them. More specifically, relationships enable you to:

Filter data in one table by columns of data from related tables. Integrate columns from multiple tables into a PivotTable or PivotChart. Easily look up values in related tables using Data Analysis Expressions (DAX)

formulas.

Review Existing Relationships

You already have data from three different sources in your PowerPivot workbook:

Sales and product data imported from an Access database. Existing relationships were automatically imported for you together with the data.

Product category data imported from an Access database. Data copied from, and linked to, an Excel spreadsheet that contains store information.

To review existing relationships

1. In the PowerPivot window, on the Design tab, in the Relationships group, click Manage Relationships.

2. In the Manage Relationships dialog box, you should see the following relationships, which were created when the first Access database was imported:

Table Related Lookup Table DimProduct [ProductSubcategoryKey]

DimProductSubcategory [ProductSubcategoryKey]

FactSales [channelKey] DimChannel [ChannelKey] FactSales [DateKey] DimDate [Datekey] FactSales [ProductKey] DimProduct [ProductKey]

3. Notice that you can create, edit, and delete relationships from this dialog box. Click Close.

Create New Relationships between Data from Separate Sources

Now that you have reviewed the relationships that were created automatically, you will create additional relationships.

5

Introduction To PowerPivot

To create your first relationship

1. Click the Stores table tab.2. Right-click the GeographyKey column header, and then click Create Relationship.

The Table box and the Column box are automatically populated.

3. In the Related Lookup Table box, select Geography (the table that you pasted in from an Excel worksheet and then renamed).

4. In the Related Lookup Column box, make sure GeographyKey is selected.5. Click Create.6. When the relationship is created, an icon displays at the top of the column. Point to the

cell to display the relationship details.

To create more relationships between the data from Access and Excel

1. Click the Stores tab.2. Select the StoreKey column.3. On the Design tab, click Create Relationship.

The Table box and the Column box are automatically populated.

4. In the Related Lookup Table box, select FactSales.5. In the Related Lookup Column box, make sure StoreKey is selected.

Notice the information icon next to the Related Lookup Column box. This tells you that this relationship is being created in the wrong order. When you create a relationship, you must select a column with unique values for the Related Lookup Column.

6. Reverse the order. Select FactSales from the Table box, and then select StoreKey from the Column box. Select Stores as the Related Lookup Table, and then select StoreKey as the Related Lookup Column.

7. Click Create.

Create Relationships in Diagram View

In Diagram View, you can easily create relationships between columns in separate tables. The relationships appear visually, which enables you to quickly see how all the tables relate to each other. In this step, you will create the last relationship that you will need to complete this tutorial using Diagram view. For more information about Diagram View, see PowerPivot Window: Diagram View.

To navigate Diagram View

6

Introduction To PowerPivot

1. In the PowerPivot window, on the Home tab, in the View area, click Diagram View. The Data View spreadsheet layout changes to a visual diagram layout, and the tables are automatically organized, based on their relationships.

2. To see all the tables on the screen, click the Fit to Screen icon in the top-right corner of Diagram View.

3. To organize a comfortable view, use the Drag to Zoom control, the Minimap, and drag the tables into the layout that you prefer. You can also use the scroll bars and your mouse wheel to scroll the screen.

4. Point to a relationship line (black line with an arrow and circle on the ends) to highlight the related tables.

To create a relationship between tables in Diagram View

1. While still in Diagram View, right-click the DimProductSubcategory table diagram, and then click Create Relationship. The Create Relationship dialog box opens.

2. In the Column box, select ProductCategoryKey, in the Related Lookup Table box, select ProductCategory, and in the Related Lookup Column box, select ProductCategoryKey.

3. Click Create. 4. Check that all relationships have been successfully created by clicking Manage

Relationships from the Design tab and reviewing the list.

Create a calculated column for Total Profit

1. In the PowerPivot window, switch back to Data View, and then select the FactSales table.2. On the Design tab, in the Columns group, click Add.3. In the formula bar above the table, type the following formula. AutoComplete helps you

type the fully qualified names of columns and tables, and lists the functions that are available. For tips on how to use AutoComplete, see Build Formulas for Calculations.

=[SalesAmount] - [TotalCost] - [ReturnAmount].

4. When you have finished building the formula, press ENTER to accept the formula.

Values are populated for all the rows in the calculated column. If you scroll down through the table, you will see that rows can have different values for this column, based on the data that is in each row.

5. Rename the column by right-clicking CalculatedColumn1 and selecting Rename Column. Type TotalProfit, and then press ENTER.

Create calculated columns for related data

1. In the PowerPivot window, in Data View, select the DimProduct table.2. On the Design tab, in the Columns group, click Add.

7

Introduction To PowerPivot

3. In the formula bar above the table, type the following formula. The RELATED function returns a value from a related table. In this case, the ProductCategory table includes the names of product categories, which will be useful to have in the DimProduct table when you build a hierarchy that includes category information. For more information about this function, see RELATED Function.

=RELATED(ProductCategory[ProductCategoryName]).

4. When you have finished building the formula, press ENTER to accept the formula.

Values are populated for all the rows in the calculated column. If you scroll down through the table, you will see that each row now has a Product Category Name.

5. Rename the column by right-clicking CalculatedColumn1 and selecting Rename Column. Type Product Category, and then press ENTER.

6. On the Design tab, in the Columns group, click Add.7. In the formula bar above the table, type the following formula, and then press ENTER to

accept the formula.

=RELATED(DimProductSubcategory[ProductSubcategoryName]).

8. Rename the column by right-clicking CalculatedColumn1 and selecting Rename Column. Type Product Subcategory, and then press ENTER.

Why Create Hierarchies?

Tables can include dozens or even hundreds of columns. Because of this, client users might have difficulties finding and including data in a report. The client user can add the entire hierarchy (consisting of multiple columns) to a report in only one click. Hierarchies can also provide a simple, intuitive view of the columns. For example, in a Date table, you can create a Calendar hierarchy. Calendar Year is used as the top-most parent node, with Quarter, Month, and Day included as child nodes (Calendar Year->Quarter>Month->Day). This hierarchy shows a logical relationship from Calendar Year to Day.

Hierarchies can be included in perspectives. Perspectives define viewable subsets of a model that provide focused, business-specific, or application-specific viewpoints of the model. A perspective, for example, could provide users a hierarchy of only those data items necessary for their specific reporting requirements. For more information about perspectives, see Perspectives Dialog Box.

Create a Hierarchy

8

Introduction To PowerPivot

You can create a hierarchy by using the columns and table context menu or by using the Create Hierarchy button on the table header in the Diagram View. When you create a hierarchy, a new parent node appears with the columns you selected as child nodes.

When you create a hierarchy, you create a new object in your model. You do not move the columns into a hierarchy; you create additional objects. A single column can be added to multiple hierarchies.

To create a hierarchy from the context menu

1. In the PowerPivot window, switch to Diagram View. Expand the DimDate table so that you can more easily see all of its fields.

Press and hold Ctrl and click the CalendarYear, CalendarQuarter and CalendarMonth columns (you will need to scroll down the table).

2. To open the context menu, right-click one of the selected columns. Click Create Hierarchy. A parent hierarchy node, Hierarchy 1, is created at the bottom of the table, and the selected columns are copied under the hierarchy as child nodes.

3. Type Dates as the name for your new hierarchy.4. Drag the FullDateLabel column under the CalendarMonth hierarchy child node. This

creates a child node from the columns and places the node under the CalendarMonth child node.

To create a hierarchy from the button in the table header

1. While still in Diagram View, point to the DimProduct table, and then click the Create Hierarchy button in the table header. An empty hierarchy parent node appears at the bottom of the table.

2. Type Product Categories as the name for your new hierarchy.3. To create hierarchy child nodes, drag the Product Category, Product Subcategory, and

ProductName columns onto the hierarchy.

Recall from the previous lesson that you added Product Category and Product Subcategory by creating calculated columns that reference these fields from related tables. One of the benefits of using the RELATED function is that you can locate fields in the same table, allowing you to create hierarchies, such as Categories, that use values from other tables.

Edit a Hierarchy

You can rename a hierarchy, rename a child node, change the order of the child nodes, add additional columns as child nodes, remove a child node from a hierarchy, show the source name of a child node (the column name), and hide a child node if it has the same name as the hierarchy parent node.

9

Introduction To PowerPivot

To change the name of a hierarchy or child node

1. While still in Diagram View, in the Categories hierarchy, right-click the FullDateLabel child node, and then click Rename. Type Date.

Notice that when you right-click a child node in a hierarchy, you have several commands at your disposal to move, rename, or hide a source column name.

2. Double-click the parent hierarchy, Product Categories, and then change the name to just Categories.

Delete a Hierarchy

Keep the hierarchies in the workbook in order to complete the tutorial, but if you want to delete a hierarchy at some point, follow these steps.

To delete a hierarchy and remove its child nodes

1. While still in Diagram View, in the FactSales table, right-click the parent hierarchy node, Hierarchy Example 2, and then click Delete. (Or, you can click the parent hierarchy node and then press Delete.) Deleting the hierarchy also removes all the child nodes.

2. Click Delete from Model in the dialog box to confirm the action.

Add a PivotTable to Your Analysis

You'll continue using the PowerPivot workbook you created in the previous tasks. It already has the data imported and relationships created. Now you will add a PivotTable.

Important Always create PivotTables from the PowerPivot window or the PowerPivot tab in the Excel window. There is also a PivotTable button on the Insert tab in the Excel window, but standard Excel PivotTables cannot access your PowerPivot data.

To Add a PivotTable to Your Analysis

1. In the PowerPivot window, on the PowerPivot Home tab, click PivotTable.2. Select New Worksheet.

Excel adds an empty PivotTable to the location you specified and displays the PowerPivot Field List. The Field List displays two sections: a field section at the top for adding and removing fields, and a section at the bottom for rearranging and repositioning fields.

10

Introduction To PowerPivot

3. Select the empty PivotTable.

If you get an error message telling you the data list is no longer valid, right-click the table and select Refresh Data.

4. In the PowerPivot Field List, scroll down and locate the FactSales table.5. Select the SalesAmount field. Ensure this field displays in the Values window of the

Field List.6. In the DimChannel table, select the ChannelName field. Move this field to the Column

Labels window of the Field List.7. In the DimDate table, select the Dates hierarchy. If necessary, move this hierarchy into

the Row Labels box.8. Rename the PivotTable by double-clicking Sum of SalesAmount in the first cell, erasing

the current text, and typing Sales by Channel.

The Sales by Channel PivotTable lists the sum of sales for Contoso and for each Sales Channel, by quarters from first quarter 2007 through fourth quarter 2009.

Expand each year to drill down into quarterly, monthly, and daily sales figures.

To Add Another PivotTable to Your Analysis

1. In the Excel window, on the PowerPivot tab, click PivotTable.2. Select New Worksheet.

Excel adds an empty PivotTable to the location you specified and displays the PowerPivot Field List.

3. Select the empty PivotTable.

If you get an error message telling you the data list is no longer valid, right-click the table and select Refresh Data.

4. In the PowerPivot Field List, scroll down and locate the FactSales table.5. Select the TotalProfit field. Ensure this field displays in the Values window of the Field

List.6. In the PowerPivot Field List, locate the DimProduct table.7. Select the Categories hierarchy. Ensure this field displays in the Row Labels window of

the Field List.8. In the PowerPivot Field List, locate the DimDate table.9. Drag the CalendarYear field from the PivotTable Field List, into the Column Labels

window.10. Rename the PivotTable by double-clicking Sum of TotalProfit in the first cell, erasing the

current text, and typing Profit by Category.

11

Introduction To PowerPivot

The Profit by Category PivotTable lists the sum of profits, by year, for each Contoso product category.

These are simple analyses of your data. To dig deeper, you will add a PivotChart and Slicers.

Delete a PivotTable

Keep the PivotTables in the workbook in order to complete the tutorial, but if you want to delete a table at some point, follow these steps.

To Delete a PivotTable

1. Click inside the PivotTable.2. In the PivotTable Tools tab, select Options.3. In the Actions group, click Select.4. Select Entire PivotTable. On the Home ribbon select Delete and then click Delete Sheet.

Add a PivotChart to Your Analysis

You'll continue using the PowerPivot workbook you created in the previous tasks. It already has the data imported, relationships created, and PivotTables added.

Important Always create PivotCharts from the PowerPivot window or the PowerPivot tab in the Excel window. There is also a PivotChart button on the Insert tab in the Excel window, but standard Excel PivotCharts cannot access your PowerPivot data.

To Add a PivotChart to Your Analysis

1. Start on the worksheet that contains your Sales by Channel PivotTable. 2. On the PowerPivot tab in Excel, click the arrow below PivotTable and select

PivotChart.3. Select Existing Worksheet and click OK.

Excel adds an empty PivotChart to the same worksheet that contains your Sales by Channel PivotTable.

4. Select the empty PivotChart and in the PivotChart Tools tab, select Design and then Change Chart Type.

5. Select the first chart in the Line group and then click OK.6. In the FactSales table, select the SalesAmount field. Ensure this field displays in the

Values window of the Field List.7. In the DimChannel table, select the ChannelName field. In the PivotTable Field List,

move this field from the Axis Fields box into the Legend Fields box.

12

Introduction To PowerPivot

8. In the DimDate table, select CalendarYear. In the PivotTable Field List, move this field from the Values box into the Axis Fields box.

The PivotChart and PivotTable now display the same data – in very different layouts.

9. Format the display of the data to make it easier to read and compare. Right-click the axis numbers and select Format Axis.

1. Click Number and in the Category list, select Currency.2. Set Decimal places to 0, and then click Close. 3. Right-click the Sum of SalesAmount axis label and select Value Field Settings.4. Change Custom Name to Sales by Channel and then click OK.

To Add Another PivotChart to Your Analysis

1. Start on the worksheet that contains your Profit by Category PivotTable. 2. On the PowerPivot tab in Excel, click the arrow below PivotTable and select

PivotChart.3. Select Existing Worksheet and click OK.

Excel adds an empty PivotChart to the same worksheet that contains your Profit by Category PivotTable.

4. In the FactSales table, select the TotalProfit field. Ensure this field displays in the Values window of the Field List.

5. In the ProductCategory table, select the ProductCategoryName field. Ensure this field displays in the Axis Fields window of the Field List.

6. In the PivotChart Tools tab, select Design and click Change Chart Type.7. Scroll down and select the first Pie chart type and click OK.8. In the Chart Styles group, select the 3-dimensional style with a black background and

click OK.9. On your pie chart, select the title (Total) and change it to Profit % by Category.10. Next, you add and format data labels.

1. On your pie chart, right-click and select Add Data Labels. 2. Right-click again and select Format Data Labels. 3. Highlight Label Options, then select the Percentage checkbox and deselect Value.4. Click Close. Resize the chart to make sure that all product categories are

displayed.11. Save your PowerPivot workbook.

Note This PivotChart displays percentage values for each product category. Because FactSales and other tables are filtered, the percentages are percentages of total sales in six of the eight categories of Contoso products.

These are simple analyses of your data. To dig deeper, you will add Slicers.

13

Introduction To PowerPivot

Delete a PivotChart

Keep the PivotCharts in the workbook in order to complete the tutorial, but if you want to delete a chart at some point, follow these steps.

To Delete a PivotChart

1. To delete a PivotChart, click inside the PivotChart.2. Right-click and select Cut.

Deleting the PivotChart does not delete any associated PivotTable reports or data.

Add Slicers to a PivotTable

To Add Slicers to the Profit by Category PivotTable

1. Click anywhere inside the Profit by Category PivotTable to display the PowerPivot Field List.

2. In the PivotTable Tools area of the Excel ribbon, click Options.3. Click Insert Slicer.4. In the Insert Slicers window, locate the Geography table and select ContinentName.5. Under the DimChannel table, select ChannelName.6. Under the DimProductSubcategory table, select ProductSubcategoryName.7. Click OK.

Format Slicers

To Format Slicers

1. Arrange the slicers so that they can all be seen. To move the Slicers, click the gray border and drag.

Move the PivotChart down and to the side to make room for the slicers.

2. The title of the ProductSubcategoryName Slicer is truncated. To format this Slicer, right-click the Slicer and select Slicer Settings.

1. In the Caption box, type Subcategory.2. Verify that Display header is selected.3. Click OK.

3. Sometimes Slicers must be resized in order to display their contents correctly. Resize the Subcategory Slicer by adding columns.

1. Right-click the Product Subcategory Slicer and select Size and Properties.2. Highlight Position and Layout.

14

Introduction To PowerPivot

3. In the Number of columns dropdown, select 2. Click Close.4. Drag the corners until all content is visible.

4. Continue to format your Slicers as needed.

Use Slicers to Analyze your PivotTable Data

To Use Slicers to Analyze your PivotTable Data

1. At Contoso we want to evaluate our sales profit trends by channel. Based on what we discover, we may have to redistribute marketing budgets and/or close channels.

1. In the ChannelName Slicer, select Catalog. Catalog should now be the only shaded item in the Slicer list.

2. By looking at the PivotTable you see that catalog sale profits are declining.3. One at a time, click Online, Reseller, and Store to reveal those profit trends. You

see that online profits are increasing, store profits are decreasing and reseller profits are decreasing slightly.

4. Clear the filters you have set by clicking the icon in the upper-right corner of the Slicer.

2. Dig a bit further by slicing your profit data by subcategory and continent. Here are several interesting things that you might discover:

1. Profits have more than doubled for cellphone accessories, televisions, and recording pens with the biggest percentage increase coming from online sales. While most sales were made in stores, store profit percentage increase was the lowest. Given that most sales come from stores, what can be done to maximize profits from this channel?

2. Cellphone accessories profits took a significant jump in 2009 for the Reseller and Store channels. Prior to that, profit increase was fairly flat in those 2 channels. To what can this jump be attributed?

3. Overall profits from the sales of televisions more than doubled from 2007-2009. However, most of that increase came in 2008 with very little profit increase seen in 2009. Why were profits flat in 2009 and how can they be increased?

4. Sales of Desktops dropped significantly. With total profits of almost 260 million, only 21 million came from catalog sales. Catalog sales saw profits drop from almost 10 million (2007) to 4 million (2009). Perhaps Contoso should close this channel?

5. Profits in Asia are increasing whereas profits in and North America are decreasing.

Contoso can use this information, and much more, to make intelligent business decisions.

To Add Slicers to a PivotChart

1. Click anywhere inside the Profit % by Category PivotChart to display the PowerPivot Field List.

2. In the PowerPivot Field List, locate the DimDate table.

15

Introduction To PowerPivot

3. Drag CalendarYear and CalendarQuarter to the Slicers Horizontal area of the PowerPivot Field List.

4. Under the Geography table, select ContentinentName. 5. To the Slicers Vertical area of the PowerPivot Field List.

To Format Slicers

1. Arrange the Slicers so that they can all be seen. To move the Slicers, click the gray border and drag the Slicers.

2. By default, Slicer items are displayed in alphabetical and numeric order, with items with no data displayed last. To change this view:

1. Right-click the CalendarYear Slicer, and select Slicer Settings.2. Uncheck Show items with no data last. Click OK.

3. Continue to format your Slicers as needed.

To Use Slicers to Analyze your PivotChart Data

1. Use the CalendarYear Slicer to explore profit by year. The PivotChart clearly shows the profit share increase for COMPUTERS and TV and VIDEO (at the expense of CAMERAS and CAMCORDERS) from 2007 to 2009. Profit share for the other categories shows almost no fluctuation.

2. To dig even deeper, use the CalendarMonth Slicer. You will discover that CAMERAS and CAMCORDERS had the highest profit share in the latter months of 2007.

Measures

In this tutorial, you will create one measure that calculates store sales, a second measure that calculates last year store sales, and a third measure that uses both of the previous measures to calculate year over year growth. You will use this last measure as the basis for a KPI that indicates whether annual growth is above, at, or below target. Creating a measure is a requirement for creating a KPI.

Note Measures used in this lesson are borrowed from the “Year Over Year Growth” scenario in the PowerPivot DAX Survival Guide. For more information, see PowerPivot DAX Survival Guide.

To create a measure that calculates store sales

1. In Data View of your PowerPivot window, click the FactSales table tab at the bottom of the window. In practice, you can place measures in any table, but for simplicity we will use the FactSales table as the logical home for all of the aggregations we create.

2. Show the Calculation Area. The Calculation Area is a grid at the bottom of each table. It contains any implicit or explicit measures that you create. To display the Calculation Area, click Calculation Area in the Home tab.

16

Introduction To PowerPivot

3. Click the first cell in the Calculation Area. It happens to be under the SalesKey column. The measures that you are creating are independent of any column in the table. We choose the first column in the grid for convenience, to more easily see our measures without having to scroll through the grid.

4. In the formula bar, type the name StoreSales.5. Next type a colon, and then begin to type the =CALCULATE() formula. As you type, the

related formulas appear below the formula bar.6. Double-click the CALCULATE formula. The formula populates as =CALCULATE in

the formula bar. CALCULATE(Expression, [Filter1], [Filter2], …) appears below the formula bar.

7. Begin to type SUM. Double-click SUM when auto-complete displays it.8. Type FactSales[SalesAmount]), DimChannel[ChannelName]=”Store”) to complete the

formula.9. Compare your formula the following formula. Pay close attention to the placement of

parentheses and brackets to avoid syntax errors:

Copy

StoreSales:=CALCULATE(SUM(FactSales[SalesAmount]), DimChannel[ChannelName]="Store")

10. Press Enter to accept the formula.

To create a measure that calculates last year’s sales

1. In the Calculation Area, beneath the SalesKey column, click the second cell from the top (under StoreSales), and then in the formula bar, paste in the following formula:

Copy

StoreSalesPrevYr:=CALCULATE([StoreSales], DATEADD(DimDate[Datekey], -1, YEAR))

2. Press Enter to accept the formula.

To create a measure that calculates year-over-year growth

1. In the Calculation Area, beneath the SalesKey column, click the third cell from the top (under StoreSalesPrevYr), and then in the formula bar, paste in the following formula:

Copy

YOYGrowth:=([StoreSales] - [StoreSalesPrevYr]) / [StoreSalesPrevYr]

2. Press Enter to accept the formula.

17

Introduction To PowerPivot

You should now have three measures to use as the basis for your KPI. In the next step, you will format each measure so that the values are more readable in the workbook.

To format each measure

1. In the Calculation Area, beneath the SalesKey column, right-click StoreSales and then select Format.

2. In the Formatting dialog box, select Currency and then click OK.3. Right-click StoreSalesPrevYr, select Format, select Currency and then click OK.4. Right-click YOYGrowth, select Format, select Number, and then choose Percentage.

Click OK.

KPIs

One of the requirements for creating a Key Performance Indicator (KPI) is to first create a base measure that evaluates to value. You will then extend the base measure to a KPI. In this tutorial, you will create a KPI based on the last measure you created, YOYGrowth. You will use this measure to add thresholds that indicate whether store performance relative to last year is on target, below target, or at target.

To create a KPI

1. Make sure you are in the Data View of the FactSales table. If the Calculation Area is not displayed, on the Home tab, click Calculation Area.

2. In the Calculation Area, under the SalesKey column, right-click the YOYGrowth measure, which will serve as the base measure (value). Because this measure is a percentage, you will use absolute values to indicate whether the percentage is above or below target.

3. In the measure’s context menu, click Create KPI (or you could click Create KPI on the Home tab in the Measures area). The Key Performance Indicator (KPI) dialog box appears.

Note Create KPI is only available for measures that you create using the approaches previously described. If you create a measure in Excel, by dragging a field from a table to the Values area in the PowerPivot field list, that measure is an implicit measure and cannot be used as the basis of a KPI. For more information, see Measures in PowerPivot.

4. In Define target value, select Absolute value, and then type 0.5. In Define status thresholds, click and slide the low threshold value to -0.05 and the high

value to 0.05.

The status thresholds indicate that 5% negative growth marks the low range, and 5% positive growth marks the beginning of the high range.

18

Introduction To PowerPivot

6. In Select icon style, click the traffic lights icon style.7. Under Select icon style, click Descriptions, and then type Tutorial example in the KPI

description box.8. Click OK to create the KPI. The KPI icon appears on the right side of the YOYGrowth

cell in the Calculation Area.

Create a Perspective

To add a perspective

1. In the PowerPivot window, make sure you are in Advanced Mode (you can see the Advanced tab). If you cannot see the tab, click the File button to the left of the Home tab, and then click Switch to Advanced Mode.

2. On the Advanced tab, click Perspectives. The Perspectives dialog box appears.3. To add a new perspective, click New Perspective.

If you create an empty perspective with all of the field object fields, then a user using this perspective will see an empty Field List. Perspectives should contain at least one table and column in order to be useful.

4. Type Sales Perspective as the name for the new perspective. The name is a required field.5. Select StoreName from the Stores table to include it in the perspective.6. Select the Categories hierarchy from the DimProduct table.7. Select CalendarYear from the DimDate table.8. Select ContinentName from the Geography table.9. Click the expand button to the left of the FactSales table to see the individual columns the

table, and then select the following columns: StoreSales, StoreSalesPrevYr, and YOYGrowth.

10. Click OK to add the new perspective and close the Perspectives dialog box.11. To rename the perspective, double click the column header (the name of the perspective)

or click the Rename button, and then change the name to Sales Report.

Use the Perspective in a PivotTable Report

In this step, you will use the perspective you just created to build a PivotTable report. You will quickly notice how much simpler it is to create a report when you use a perspective that excludes the tables and fields not relevant to the analysis.

To create the report

1. In the PowerPivot window, on the PowerPivot Home tab, click PivotTable.2. Select New Worksheet. 3. Select the empty PivotTable.

19

Introduction To PowerPivot

If you get an error message telling you the data list is no longer valid, right-click the table and select Refresh Data.

4. In the PowerPivot Field List, at the top of the list, click the down arrow next to [Default Perspective] and select Sales Report.

5. In the Stores table, select the StoreName field. Ensure this field displays in the Row Labels window of the Field List.

6. In the DimDate table, select the CalendarYear field. Ensure this field displays in the Column Labels window of the Field List.

7. Filter the CalendarYear field so that only data from 2008 and 2009 is used in the PivotTable.

In the PivotTable, click the Filter icon by Column Labels.

Clear Select All, and then select 2008 and 2009.

8. In the FactSales table, select StoreSales, StoreSalesPrevYr, and YOYGrowth. Beneath YOYGrowth, verify that both Value and Status are selected.

9. In the Geography table, drag ContinentName to the Slicers Vertical area.10. One at a time, click Asia, Europe, and North America to view the annual store sales

metrics for each continent.

Use the Slicers and KPIs to Analyze your PowerPivot Data

At Contoso we want to evaluate annual store sales by territories. Based on what we discover, we may review marketing budgets and/or close stores to improve the numbers.

1. In the ContinentName Slicer, select Asia. The KPIs provides a visual indicator that lets us quickly identify which stores are below target.

2. Click North America to reveal the declining trends in that market. As we can see from the KPIs, there appear to be market differences that go beyond individual store performance, with widespread decline for the majority of stores.

3. To further analyze the trends, let’s add the Categories hierarchy to the analysis. Expand DimProduct and drag Categories to the Rows area.

Adding Product Categories shows us that for many stores in North America, Audio is above target, while other categories are consistently below target. To what can we attribute this pattern?

4. For Europe, the KPIs show us a different pattern, with specific stores exceeding or failing in all categories. Further investigation will tell us whether we need to close individual stores for that region, or adopt the selling strategies of the successful stores more broadly across the channel.

20