Welcome to MSPTDA video number 13. Over the last 12 videos we have been studying Power Query, and now we want to study Power Pivot. We are going to have three introductory videos. I want to start off with video number 3, Power Pivot Intro #3, which will be a comprehensive introduction to Excel Power Pivot: the Data Model, DAX, and the power of Power Pivot. But before we get to that comprehensive introduction, I want to show you two awesome tricks for Excel, where we use Power Pivot not to its full extent, but just to help us in Excel.
In video number 2, we will see how to use Power Pivot to import 3 million rows into Excel. In this video, we will see how to use the Relationship feature to replace VLOOKUP. Now look at this. There is a big red line through VLOOKUP. That does not mean that in Excel we do not have hundreds of awesome uses for VLOOKUP. But when we use VLOOKUP in a helper column attached to a proper data set that we are going to use as source data for a pivot table, we do not want to use VLOOKUP.
Let's go look at what I mean. Here is an example of the revenue table. Here is the lookup for country and the lookup for product. We want to avoid having VLOOKUPs look something up and retrieve it. This VLOOKUP is fine on a small data set. But we have 73,000 rows here. That is a lot of formulas, and we had to do it twice. So instead of using VLOOKUP, we can use relationships. If you have never done a relationship before, it is the same idea as VLOOKUP. What is this formula doing? It is looking up product in this table. But remember, the first column of any lookup table has a unique list of items. That means there is exactly one of each item. Over here in this column, of course, we can have multiple listings of products. Anytime you have this situation, one-to-many, a lookup table over to a fact table or a sales table, we can use the Relationship feature rather than VLOOKUP.
The relationship feature is only one part of Power Pivot. Before we jump over to Excel, I want to talk about what Power Pivot is. This will be a basic answer; in intro video number 3, we will cover it in more detail. First off, Power Pivot automatically comes in Office 365. It has been around in earlier versions as far back as 2010, but it was either an add-in, or you had to buy the correct version of Excel, and sometimes that was difficult.
Excel Power Pivot provides three data tools. The columnar database is amazing. It is a behind-the-scenes, in-RAM-memory, efficient big data analytics database. We will talk more about the exact structure of that columnar database two videos ahead, but it is what allows us to hold big data with a small file size. Relationships between tables is another feature of Power Pivot. And then DAX formulas, which are formulas we get to create and use in pivot tables. We do not get to see DAX formulas in this video, but two videos ahead we will learn DAX for the first time.
The columnar database is what holds the big data. Relationships between tables mean we do not have to use VLOOKUP, and DAX formulas are the calculations. Together, those three items make up the Data Model. So when you hear the words data model, think of the columnar database, the relationships, and the DAX formulas. From the Data Model, we make pivot tables. To distinguish between standard pivot tables and Data Model pivot tables, I will always refer to them as Data Model pivot tables.
The basic advantages of using Excel Power Pivot are that we can work on millions of rows of data, we can use relationships between tables and have multiple tables in our pivot table field lists, and we can use DAX formulas. DAX formulas, as we will see a couple of videos ahead, provide more variety than a standard pivot table, and they are specifically designed to work efficiently on big data.
Now let's go over to Excel. We are in our Start file, and we have the same tables 1, 2, and 3. In order to get data from an Excel sheet into Power Pivot or Power Query, as we have been doing for the last 10 videos, the data has to be in an Excel table. I have already converted these two tables. I will click on the product table, press Control-T to convert it to an Excel table, and enter. I want to make sure to name it, so under Table Tools Design, over to Properties, I will name this Product Lookup Table and enter.
This video is only going to show us how to use relationships to replace VLOOKUP, but there are two other important things we want to learn. One is that if you compare file size with two VLOOKUP columns versus using relationships, the file size is much smaller. Also, this trick works no matter what version you have, Excel 2013, Excel 2016, or Office 365. I am going to start off pretending I do not even have Power Pivot, because over in the Data ribbon tab, under Data Tools, there is the Relationships button. This is a secret backdoor way to build relationships and put these tables into the Data Model, which is a much more efficient place to store data.
Here is how we do it. In Data Tools, I click Relationships, then New. We have to look at this: it says Table and Related Table. Table is always going to be our Fact Sales table. Related Table is always going to be the Lookup table. There is a hint here for database people. For the prerequisites for this class, we know the difference between a primary key and a foreign key. A primary key means that is the first column of the lookup table, and it must have a unique list. A foreign key means the same key, but it can have many repeats. One-to-many. So we select, and notice that it says Worksheet for each of these. There is our Sales table, so I select that. We first build a relationship to the Product table, which is the foreign key side. I select it, and notice it says Worksheet Table Product Table and then the primary key. I click OK.
When we come back to the Manage Relationships dialog box, there is the relationship: Sales table, the fact table, the many side, the foreign key. There is the lookup table, or dimension table, whose first column has a unique list. This is the one side, the primary key side. Now let's create our second relationship. Watch what happens when I click New and then go to the Table dropdown. It tells us, from this dropdown, Data Model Product Table and Data Model Sales Table. Even though we do not have the official Power Pivot add-in, it still allows us, through relationships, to add tables to the Data Model.
We are going to create our second relationship on the Sales table, using Country Code. The Related Table, the lookup or dimension table, is going to be Country, and notice it has not been added to the Data Model yet. I select Worksheet Table Country, then the primary key, the one side, the first column of the lookup table, Country Code. When I click OK, I have my two relationships. I close this. Now there is a relationship between our Sales, or Fact, table and these two lookup, or dimension, tables. The tables and relationships are stored in the Data Model.
We will look at the Data Model in a second, but remember, this trick assumes we do not have the correct version for Power Pivot, and in fact we have not even added the Power Pivot ribbon tab. So we continue assuming we do not have Power Pivot. I insert a pivot table, or use the keyboard shortcut Alt-N-V. Even though we do not have the right version, the Create PivotTable dialog box knows that the Data Model is behind the scenes and assumes we want to use it. I click OK. Here is our pivot table and the pivot table fields, and there are four tables: Country, Product, Sales, and so on. Where did Daily Sales and Employee Cost come from? Anytime we invoke a pivot table, it shows us all of the different Excel tables or Data Model tables in our pivot table field list. If we go over to Extra Tables, here is one table that came from a Power Query import, so they all show up.
Hopefully you know the names of your tables; that is an easy way to tell. Since we are using Office 365, all of these icons look the same. In earlier versions, Excel 2016 and 2013, only the Data Model pivot tables had a dark line across the top, and the other Excel tables from the workbook did not. So we cannot tell by the icon in Office 365, but if I hover my cursor, it tells me information about the table. It says Model Table Name for the Data Model tables, and for the others it just says the data source. That is another way to tell.
What we want to do is move them to Active. I right-click and choose Show in Active. Now we can go over to Active and pull down the middle part, and there is our Data Model. We are allowed to pull fields from any one of these tables. We drag Country from Country Lookup down to Rows, and instantly we get a unique list. Then we drag Product down below Country, and there is a unique list of products. Then we drag a Number field from Revenue into the Values area, which creates our calculation with two conditions or criteria. That number is the total for the product in Algeria.
Something very important about what we just did: we are essentially using relationships, which are part of Power Pivot and the Data Model, as a substitute for VLOOKUP. When we drag a Number field into Values, it looks like a standard pivot table calculation. But as we will learn two videos ahead, this is actually a DAX formula. It is an implicit measure. When we get to building full data models, we will not use implicit measures. But if you are simply using the Relationship feature to connect multiple tables you have in Excel to build some pivot tables, it is perfectly all right to drag and drop a Number field and get what looks like a standard pivot table calculation. Microsoft did this for a reason: for casual uses of relationships, Power Pivot in the Data Model accommodates people who simply want to make a pivot table quickly and easily.
One last thing: we want to show the Power Pivot ribbon tab and look at the Data Model. I go to File, then Options, then Add-ins, then Manage. From the dropdown, I choose COM Add-ins and click Go. If you have Power Pivot in earlier versions, or, as we do here with Office 365, where Power Pivot is automatically in Excel, you still have to come here, check the COM Add-in, and click OK. Now we have our Power Pivot ribbon tab. If we click Manage Data Model on the Power Pivot ribbon tab, or over in Data, Manage Data Model, it opens the Power Pivot for Excel window. This lets us look at the Data Model, and there are the tables. These tables are not stored like this; this is just our picture of the Data Model. Remember, there is a columnar database behind the scenes that stores things efficiently.
We go over to View, Diagram View. I already moved these tables around; usually they do not come as neat and tidy as this. There it is: the Fact Sales table and our two lookup, or dimension, tables, with one-to-many relationships. I close this. Two videos ahead, we will deal with this window and do lots of cool things with Power Pivot.
So in this video, the Data ribbon tab button is awesome. When you want to replace VLOOKUP using relationships, there it is. If you liked this video, be sure to click the thumbs up, leave a comment, and subscribe, because there are always lots more videos to come from Excel Is Fun, including video number 14 in this class. In the next video, Power Pivot Intro #2, we will see another Excel Power Pivot trick: using the Power Pivot Data Model along with Power Query to import and store millions of rows of text data in Excel. We will see you in the next video.
