官术网_书友最值得收藏!

Creating the model

An Excel workbook can only contain one tabular model and that one model contains tables of data (which may or may not be related). The first step to create a model is to import data into it. There are many techniques to do this—some techniques have advantages over others but for now, let's only consider the fact that we want to load data that exists in an Excel worksheet into the model.

Tip

The installation instructions for PowerPivot in Excel 2010 are covered in the Appendix, Installing PowerPivot and Sample Databases, of this book.

Getting ready

Open the Excel workbook named SalesBook which is available from the Packt Publishing website to examine the worksheets within the book. Each sheet contains a dataset for Products, Subcategories, Categories, Customers, Dates, and Sales.

How to do it…

This recipe looks at importing data into the PowerPivot model through linked tables. These are very convenient to use when the data is stored in Excel. Additionally, once the data has been imported into PowerPivot, it retains a connection to the Excel table. This means that, when the data is changed in Excel, it can also be changed in the PowerPivot model.

  1. Let's start by importing the product list. Select the Product List sheet and select cell A1.
  2. Then, on the PowerPivot tab, click on the Create Linked Table button.

    Tip

    Excel will automatically highlight the data range.

    How to do it…
  3. A small window will open confirming the data range with a checkbox for table headers. Select the checkbox and press OK.
  4. The PowerPivot window will open and the data from the Product List sheet will be imported. Note that the table appears as a tab which is similar to Excel and is called Table1. Also, note that the PowerPivot window is a separate window than the Excel workbook, so that we can return to Excel.
    How to do it…
  5. Repeat this process for all the remaining datasets except Customers.

How it works…

When a linked table is created in PowerPivot, Excel creates a named range in the Excel workbook. This is then linked to the PowerPivot model (note that there is a small chain symbol before each of the tables). Also, note that the tables in Excel are formatted with alternate blue coloring. The named ranges can be viewed in Excel by clicking on the Name Manager button on the Formulas tab.

How it works…

There's more…

A table (table range) is actually an Excel feature that PowerPivot utilizes. A table can be defined in Excel, given a meaningful name and then imported into PowerPivot, so that the name of the table in PowerPivot is the same as the named range in Excel.

Ensure that the Customers sheet is selected in Excel and also any cell in the Customers data is selected. In the Home tab, click on the Format as Table button, and choose a table style; the style chosen in the following screenshot is a relevant one:

There's more…

Note that the data is now formatted with alternating colors (based on the selected style). Return to the Name Manager window and double-click the table that relates to the Customers worksheet. A new window will open allowing you to edit the name, replace the name Table6 with Customers, and click on OK. The Table6 name is replaced by Customers in the Name Manager window.

There's more…

Now, create a linked table in the same manner as we did before and note that the name of the table imported into PowerPivot is Customers.

Tip

If you want to select an entire table in Excel, simply choose the table name from the Name Box drop-down list in the formula bar in the upper-left corner. This is shown in the following screenshot:

There's more…
主站蜘蛛池模板: 洛川县| 靖安县| 法库县| 普宁市| 墨玉县| 河曲县| 林州市| 西峡县| 额尔古纳市| 固始县| 逊克县| 连山| 巴东县| 赤峰市| 永登县| 通州市| 韩城市| 兴山县| 深水埗区| 琼海市| 四子王旗| 海宁市| 宝兴县| 拜泉县| 蒲江县| 湘西| 柳河县| 鹿邑县| 鹤壁市| 公安县| 大渡口区| 河西区| 甘南县| 砀山县| 石棉县| 澄迈县| 棋牌| 图木舒克市| 满洲里市| 盐城市| 霍州市|