Tutorial: Optimize a Sample PowerPivot Model for Power View Reports
Important
Please visit the most up-to-date Power View documentation on office.microsoft.com. Power View is now a feature of Microsoft Excel 2013, and is part of the Microsoft SQL Server 2012 Reporting Services add-in for Microsoft SharePoint Server 2010 and 2013 Enterprise Editions.
In this tutorial, you modify an Excel workbook in PowerPivot for Excel to make a small but functional model that you can use as a basis for sample Power View reports. Everything you do in this tutorial in PowerPivot, you can also do in tabular models that you create in SQL Server Data Tools (SSDT). In fact, you can do much more in SQL Server Data Tools (SSDT). For more information, see Tabular Modeling (SSAS Tabular).
The PowerPivot file and Power View report based on it
Prerequisites
To do this tutorial:
Install PowerPivot for Excel.
Have a computer that meets the System requirements for Power View.
Download and install Power View samples, including the image files, from the Download Center. For more information, see Power View and PowerPivot HelloWorldPicnic Samples for SQL Server 2012 and Images for Power View and PowerPivot HelloWorldPicnic Samples in SQL Server 2012 Samples.
Note
HelloWorld_Picnic is a tiny sample data model that demonstrates how to set data model properties to best present that data in Power View reports. In the scenario, the data is used to plan and track food and drink for picnics.
In This Article
Before you start the tutorial
Create linked tables in PowerPivot
Start Power View
Create relationships in PowerPivot
View changes in Power View
Set reporting properties in PowerPivot
Create table and cards with default values in Power View
Consolidate tables and add image URLs in PowerPivot
Try adding images in Power View
Identify image URLs in PowerPivot
Add images to a table in Power View
Default aggregates, dates, tooltips, and calculated measures and columns in PowerPivot
Create a bubble chart in Power View
Create a slicer to validate the model
Summary
Before you start the tutorial
Before you can start the tutorial:
Save the HelloWorldPicnicModelPowerPivotTutorialRTM.xlsx file to a SharePoint document library or PowerPivot Gallery.
If you save it in a SharePoint document library, you create a shared data source that points to the HelloWorldPicnicModelPowerPivotTutorialRTM.xlsx file that you saved in the SharePoint document library.
If you save it to a PowerPivot Gallery, it doesn’t need the shared data source. You can open Power View directly from the gallery.
Save the images to the associated SharePoint document library. See more information about the Images for Power View and PowerPivot HelloWorldPicnic Samples
To create a shared data source (RSDS) file to point to the PowerPivot (XLSX) file
In Shared Documents, create a HelloWorldPicnicSQL2012 folder, and save the HelloWorldPicnicModelPowerPivotTutorialRTM.xlsx file there.
In the HelloWorldPicnicSQL2012 folder, click the Documents tab, click the arrow next to New Document, and then click Report Data Source.
If there is no Report Data Source option on the New Document tab, then someone with adequate permissions on the SharePoint site needs to add that content type to the site. For more information, see Add Report Server Content Types to a Library (Reporting Services in SharePoint Integrated Mode).
In the Name box, type HelloWorldPicnicRSDS.
Note the RSDS file extension.
In the Data Source Type box, click Microsoft BI Semantic Model for Power View.
The Connection string for an XLSX file is the full URL to the file, including the file name. For example:
http://<myserver>/Shared%20Documents/HelloWorldPicnicSQL2012/HelloWorldPicnicModelPowerPivotTutorialRTM.xlsx
For Credentials, click Windows authentication (integrated) or SharePoint user.
Click Test Connection.
You see a message that the connection test was successful.
Click OK.
To save the images
Create an Images folder in the HelloWorldPicnicSQL2012 folder. For example:
http://<myserver>/Shared Documents/HelloWorldPicnicSQL2012/Images
In the Images folder, save the images that you downloaded from the Download Center. For more information, see the Prerequisites section at the beginning of this tutorial.
To start PowerPivot from the PowerPivot Gallery
From the PowerPivot Gallery, click the image of the file HelloWorldPicnicModelPowerPivotTutorialRTM.xlsx.
The workbook opens in SharePoint.
Click Open in Excel.
Click the PowerPivot tab, and then click PowerPivot Window.
To start PowerPivot from Shared Documents
From Shared Documents, click the dropdown arrow next to HelloWorldPicnicModelPowerPivotTutorialRTM.xlsx, and click Edit in Microsoft Excel.
Click the PowerPivot tab, and then click PowerPivot Window.
In Excel and PowerPivot
Create linked tables in PowerPivot
In the Excel window, select all the columns and rows in the Items worksheet.
On the Home tab, click Format as Table, and then pick a format for the table. You can make the style anything you like.
On the PowerPivot tab, click Create Linked Table.
Make sure it contains the correct columns and rows and that My table has headers is checked, and then click OK.
The table opens on a new tab in PowerPivot.
Right-click the tab and rename it Items.
Repeat this three times to create linked tables in PowerPivot for Distributors, Quantities, and Dates.
Click Save, and you now have a model—not much of a model, but a model nonetheless.
Note
You’re back in the Excel window after you save.
In Power View
Start Power View
From Shared Documents
- In the Shared Documents folder, click the arrow next to HelloWorldPicnicRSDS.rsds, the shared data source you created earlier in this tutorial, and then click Create Power View Report.
From PowerPivot
- In the PowerPivot Gallery, click the Create Power View Report icon in the upper-right corner of the HelloWorldPicnicModelPowerPivotTutorialRTM.xlsx band.
Start a report
Power View opens to a blank view. The field list on the right contains the tables you created in PowerPivot: Dates, Distributors, Quantities, and Items.
Expand the Items table.
There are the fields from the table in PowerPivot.
Click the Items table name itself.
Nothing happens. We’ll come back to this later.
Click the Name field.
You now have a table with one column, the Name column.
Note, though, that now all the other tables are grayed out, unavailable. Why?
In PowerPivot: Create relationships
The other tables are grayed out because there are no relationships between the tables in the model.
To create relationships in PowerPivot
In the PowerPivot Window on the Home tab, click Diagram View.
You see the tables in your model, with no relationships between them.
Drag the tables so you can see them all in the window. Place the Quantities table in the center, as it is central to the model.
Drag from the ItemID field in the Items table to the ItemID field in the Quantities table.
PowerPivot creates a one-to-many relationship between the two tables. It doesn’t matter which way you drag. The one and many sides of the relationship are the same. For more information about one-to-many relationships, see Guide to table relationships (from Microsoft Access Help).
Drag these fields to create other relationships between:
The Date field in the Dates and Quantities tables.
The DistribID field in the Items and Distributors tables.
Save the Excel (XLSX) file, thus saving your model.
In Power View
When you make changes to the model, you need to refresh the report. There are two Refresh buttons to choose from:
The Refresh button in the Power View Quick Access toolbar refreshes the data, if the data in the model has changed.
The Refresh button in Internet Explorer refreshes the model, but deletes any changes you’ve made since you last saved.
Click the Power View Refresh button.
Note that nothing changes.
Click the Internet Explorer Refresh button.
In this case we haven’t made any changes worth saving, so click Leave this page.
The field list is still there but the view is blank.
Expand the Items table, and drag the Name field to the view.
Note that the other tables are not grayed out. Note, too, that there is only one “apple” value.
Expand the Quantities table and drag the Qty Served field to the Name table.
Now there are many “apple” values. The Qty Served values are not being aggregated.
Try scrolling down the list.
Note that the scroll bar gets smaller as Power View retrieves more values. Power View retrieves values only as needed, to speed performance.
In the layout (lower) section of the field list, click the dropdown arrow next to the Qty Served field and then click Sum.
In PowerPivot: Set reporting properties
Time to set reporting properties to make reports based on this model work better.
In the PowerPivot Window on the File menu, click Switch to Advanced mode.
Go to the Items table.
On the Advanced tab, click Table Behavior.
For Row Identifier, click ItemID.
Note that now the rest of the items in the dialog box are available. Until you have selected a row identifier, they are all grayed out.
For Keep Unique Rows, click Name.
Thus, even if there are two identical values in this column in two different rows, Power View doesn't aggregate them if they have different ItemID values. For example, “apple”: There are two different “apple” values in the Name field. Power View no longer aggregates them, as it did earlier.
For Default Label, click Name.
Click OK.
Click Default Field Set.
Add Name, Category, and Color, and then click OK.
These fields are the defaults that are added to a view in Power View if you click the table name rather than an individual field.
Save the Excel (XLSX) file to save your model.
In Power View: Create a table and cards with default values
Click the Internet Explorer Refresh button.
Because you haven’t saved the report yet, you lose the few changes you have made.
Click Leave this page.
Expand the Items table.
Note the icon next to the ItemID and Name fields indicating that they are unique fields and the default label for this table.
Drag the Name field to the view.
Note that there are now two apple values.
Click the Undo button.
Click the Items table itself.
This creates a table with the fields you identified as the default fields for this table: Name, Category, and Color.
With this table selected, click the dropdown arrow in the Visualizations Gallery and click Card.
Note that the values from the Name field are displayed prominently, because Name is the default label field for the Items table.
Click someplace on the blank view so the cards are not selected.
In the fields (upper) section of the field list, expand the Distributors table.
Note that it contains only the Distributor and DistID fields.
Save the Power View report someplace on the SharePoint site.
In PowerPivot: Consolidate tables and add images
We can consolidate the single field from the Distributors table into the Items table to clean up the model.
To create a calculated column
In the PowerPivot window in the Items table, right-click the Add Column column and click Insert Column.
Select the new column, right-click, click Rename, and rename it Distributors.
In the Excel formula box, type
=RELATED(Distributors[Distributor Name])
Note that the formula autocompletes as you type. You can use autocompletion to make sure you have the right syntax.
The Distributor name is now in the Items table, so report creators no longer need the Distributors table or the DistID field in the Items table.
Right-click the DistID column, and then click Hide from Client Tools.
This hides the column in Power View, but you can still see it in PowerPivot.
Right-click the Distributors table tab and click Hide from Customer Tools.
Add images to the model
Before you can add images to the model, download them from the Microsoft Download Center and save them to the SharePoint site. For more information, see the Before you start section.
Add a calculated column to the Items table and call it Image Name.
Paste in this formula:
=IFERROR(IF(FIND("apple",[Name])>0, SWITCH(Left([Color],1),"b","applejuice","g",[Name]& "g","r",[Name],[Name]),[Name]),[Name])
This column makes the image names correspond to the item names in the Name field.
Add another calculated column and name it Photo. Paste in this formula, and replace <servername> with your server name:
="http://<servername>/Shared Documents/HelloWorldPicnicSQL2012/Images/rs_crescent_picnic_image_" & [Image Name] & ".png"
Each item has an associated photo. This formula concatenates the name in the Image Name column with the URL where the images are located, plus the .png file extension.
Add another calculated column and name it Drawing. Paste in this formula, and replace <servername> with your server name:
="http://<servername>/Shared Documents/HelloWorldPicnicSQL2012/Images/rs_crescent_picnic_drawing_" & [Image Name] & ".png"
Each item has an associated drawing, too.
Add another calculated column and name it Category Drawing. Paste in this formula, and replace <servername> with your server name:
="http://<servername>/Shared Documents/HelloWorldPicnicSQL2012/Images/rs_crescent_picnic_drawing_" & [Category] & ".png"
Each category has an associated drawing.
Add one more calculated column and name it Category Photo. Paste in this formula, and replace <servername> with your server name:
="http://<servername>/Shared Documents/HelloWorldPicnicSQL2012/Images/rs_crescent_picnic_image_" & [Category] & ".png"
Each category has an associated photo, too.
Save the Excel (XLSX) file to save your model.
Note that you are back in the Excel window, and the calculated columns don’t appear. They are only in PowerPivot.
Let’s see how it looks in Power View.
In Power View: Try to add images to a table
Click the Internet Explorer Refresh button.
Because you have saved the report, you don’t lose the changes you have made.
Note that there are only three tables now—the Distributors table is gone.
Expand the Items table.
Note the new fields, including the Distributor field.
Drag the Photo column to the table on the view.
Uh oh! That’s no photo. That’s just the URL. Back to the model.
In PowerPivot: Identify image URLs
Click the Items table, then the Advanced tab.
Check the Image URL box for all four URL fields.
Click Table Behavior.
Set the Default Image to Drawing, and then click OK.
Click Default Field Set, and add Drawing to the Default fields set.
Click OK.
Save the Excel (XLSX) file to save your model.
In Power View: Add images, dates, and numbers to a table
To add images
Click the Internet Explorer Refresh button.
You lose the most recent changes you made.
Add the Drawing field to the table.
There are the images!
Now let’s look at dates and numbers.
To add dates and numbers
Click the blank space in the view to start a new visualization.
Expand the Dates table and drag the Month Name field to the view.
From the Items table, add the Category field to the same table.
Note that none of the charts in the Visualizations Gallery are available. A chart needs at least one aggregated value.
In the Quantities table, click the dropdown arrow next to the Qty Served field, and click Add to Table as Sum.
Now that the table has a field with a sum, the charts are available.
The Qty Served field contains whole numbers. Power View does not aggregate them by default because whole numbers might be in a field that shouldn’t be aggregated, such as a key field. You can change that default behavior in the model.
Click Line Chart.
You should see:
Qty Served in Values.
Month Name in Axis.
Category in Series.
If not, drag the fields to the right boxes.
But something is wrong: The months start with April, August, and December, and end with September. They’re alphabetical, not chronological.
Back to the model.
In PowerPivot: Default aggregates, dates, tooltips, and calculated measures and columns
Calculated columns calculate a result and store it for every row in a table. Calculated measures are calculated on the fly, depending on the context—where they are being calculated in a PivotTable or in a Power View report. For more about calculated columns and measures, see Build Formulas for Calculations.
To set month order
In the PowerPivot window, go to the Dates table.
On the Design tab, click Mark as Date Table.
Select the Date field and click OK.
Note
The values in the Date field must be unique.
Select the Month Name column, and on the Home tab, click Sort by Column and then Sort Month Name by the Month Number column.
Select the Month Number column, right-click, and click Hide from Client Tools.
Repeat steps 4 and 5 for the Day Name and Day Number fields.
To set default aggregates
In the PowerPivot window, go to the Quantities table.
Select the Qty Served, Qty Consumed, and Attendees columns.
On the Advanced tab, click Summarize by, then click Sum.
To set a description
Right-click the Qty Served column, click Description, and type:
How much we served.
This text will appear as a tooltip over the Qty Served field in the fields (upper) section of the field list. You can add a tooltip to every table and field.
To create a calculated column
In the Quantities table, insert a column and rename it Leftovers. In the Excel formula box, type:
=[Qty Served]-[Qty Consumed]
PowerPivot autocompletes the column names as you type.
Select the Leftovers column and on the Advanced tab, click Summarize by, then click Sum.
To create a calculated measure
Still in the Quantities table, click in any cell in the lower part of the table, below the dividing line.
This area is called the measure grid. You can hide or show it with a button on the Home tab. You can put measures in any cell in any column.
Paste the quantity served year-to-date formula in the Excel formula box:
Qty Served YTD:=TOTALYTD(SUM([Qty Served]),Dates[Date])
Save the Excel (XLSX) file to save your model.
In Power View: Create a bubble chart
Click the Internet Explorer Refresh button.
What has changed?
The line chart refreshes to put the month names in order.
The Quantities table in the field list has new numeric fields such as Qty Served, with little calculator symbol next to them. The Qty Served field now appears two times—one is aggregated as a measure, and the other isn’t aggregated. You could hide the unaggregated column in the model.
Also in the Quantities table, the new Qty Served YTD measure has the little calculator symbol next to it.
In the fields section of the field list, hover over the Qty Served field.
The tooltip appears.
Create a table with the Name, Qty Served, Qty Served YTD, and Leftovers fields.
In the Visualizations gallery, click Scatter chart.
Make sure the Qty Served YTD field is in the X Value box.
Drag the Month Name field from the fields section of the field list to the Play Axis box in the layout (lower) section of the field list.
Click the play arrow.
Note that the bubbles gradually move from left to right, as the Qty Served YTD values increase.
In Excel: Validate the model
You can also validate that your model has published correctly by creating and testing a slicer on your data in Excel. You save your XLSX file to the SharePoint site, which you have already done. You create a PivotTable and add slicers to it in Excel. In the XLSX file on the SharePoint site, you click a slicer, and it sends a query that tests the data connection. If the slicer is successful, that proves that the embedded PowerPivot model has been successfully deployed and that the credentials are configured correctly.
In the PowerPivot window, on the PowerPivot tab, click PivotChart, then New Worksheet.
Note that the new worksheet displays the PowerPivot Field List on the right.
From the Dates table, drag Month Name to Slicers Horizontal.
From the Items table, drag Color to Slicers Vertical, and Type to Slicers Horizontal.
From these tables:
Items table: drag Serve to Legend Fields.
Items table: drag Category to Axis Fields.
Quantities table: drag Leftovers to Values (note that it is automatically aggregated as a Sum).
Right-click the chart and click Change Chart Type.
Click Stacked Column.
Click the different values in the slicers to filter the chart.
The slicers work, so the PowerPivot model embedded in the Excel workbook is successfully deployed and the credentials are configured correctly.
Summary
You’ve seen how you started with raw data, and then:
Created relationships.
Set reporting properties, identifying:
Unique values.
Default labels.
Default images.
Default fields in a table.
Added calculated columns and a measure.
Consolidated tables.
Set number format.
Bound date name fields to number fields for order.
Brought in images.
And you’ve seen how those changes changed the way the data appeared in the report.
Next Steps
Now that you’ve completed this tutorial, you can use the model you have created to try Tutorial: Create a Sample Report in Power View in Power View Samples for SQL Server 2012 and SQL Server 2012 Samples Readme.