Welcome to Power Pivot video number 13. If you want to download this workbook and follow along, click on the link below the video. If you've been watching this series, videos 1 to 12, we've already covered this topic, but I want to make a quick video and compare and contrast grouping dates in an Excel PivotTable and a Power Pivot PivotTable. What we're going to do is take this table and dump it into an Excel PivotTable and see that we can group by dates, meaning we want to group by months and years and roll up the revenue into months and years. Then we'll try it in Power Pivot and see that the same feature in Excel does not exist over in Power Pivot, so we'll have to do it a different way.
I'm going to insert a PivotTable with Alt+N+V and dump it on this sheet just to compare and contrast. Let's put it in F1 and click OK. Here's how easy it is in Excel. The rule of thumb is: if all you want to do is quickly group by month and you don't have all of the things that make Power Pivot necessary, then use a PivotTable. Check this out. We simply drag Date down to Rows, come over, right-click, and choose Group. It's that easy. We say months and years, and we can see the span there, so we definitely need years. Click OK. Drag and drop Revenue, and just like that we get our PivotTable. PivotTables never work like that with row labels, so we come up to Design, Report Layout, and choose either Outline or Tabular. I'm going to do Outline. We definitely want to right-click and not format Sales; we do number formatting, which formats the field, not the actual sales. I'm going to say Currency. You can see how easy it is. That is profound: how quickly we can group by month and year in a normal Excel PivotTable.
Here's how you'd have to do it if we are using Power Pivot. Click in the table, go over to Power Pivot, and I'm going to say Add to Data Model. Again, we wouldn't do this if it was a simple table, but if you're building a model for reporting, with multiple sources of data or big data, then you have to bring it into Power Pivot and build your reports there. Now let's just try a PivotTable. I'm going to put it on a new sheet and drag and drop from this one table to Date. Come over here, right-click, and it's just not there. There's no grouping feature. You're not going to believe this, but it's actually quite a number of steps.
I'm going to come over to the data and build a calendar table. First I'm going to hunt through this data set and see what the Max and Min are. So I type =MAX, then Control+Shift+Down Arrow, Shift+Enter to put the formula in the cell, then jump up with Control+1 and tab and arrow down to Date and Enter. I'll copy this down just to quickly cheat and do Min. Actually, what I did there is copy the number formatting and the Max and change it to Min, because the table formula nomenclature works. It looks like I have to span from 2015 to 2018. Now I'm going to come over here and call this Date, Control+Enter, and I'm simply going to type the first day, 1/1/2015, and Control+Enter. Then I'm going to build this table to the end of 2018. I'll point to the little fill handle in the corner, and when I see the crosshair, I'll right-click, drag down and back, and let go. A message pops up, and I want to point to Series, and say Fill Columns, because it's going to fill down through the columns. The step value is one, and I'll end at 12/31/2018. Click OK, and just like that, with Control+Down Arrow, I have all of the dates.
Now we're going to convert this to a table with Control+T and Enter. We can come up to Design and name it there, or use Alt+J+T+A. There we see the name highlighted. I'm going to call this DCalendar and press Enter. With that selected, I'll go up to Power Pivot and Add to Data Model, or use Alt+B and then Y, Y to add it to the data model. You've got to be kidding me, that is a lot of steps.
I'm going to format this as a date. Now I have to come over to the second column, and if I want months and years, I have to do a bunch of steps. Watch this. I'm going to say Month Number and press Enter. This is called a calculated column. I'm going to type =MONTH, and as soon as I start typing in the cell, I jump up to the formula bar. The name of this table is DCalendar, so I'm going to type DC, Down Arrow for DCalendar, then [Date], close parentheses, and instantly I get the month number. Now I want Month Name, and I'll type Month Name rather than Month, because I want this to show up in the field list over my PivotTable. I'm going to hide that. Press Enter. In Excel we would use the TEXT function, but here we use =FORMAT. We use FORMAT on the value DCalendar[Date], with the number formatting custom "mmm" for the three-letter month abbreviation, in double quotes, close parentheses, and Enter.
Now I'll double-click and call this Year, press Enter, and enter the function =YEAR, which works just like Excel: DC, Down Arrow, and Enter. Notice there are no cell references over here in Power Pivot. They're all table names and field names. If we try to build a PivotTable on an existing worksheet, no, I want a new worksheet. Click OK. Now we have two tables. When we drag Month down to Rows, my heavens, we're having all sorts of trouble compared to a normal PivotTable. Alt+Tab to go back over to Power Pivot. Check this out: we have to sort this, because in the PivotTable it's doing it alphabetically. We have to sort it based on the Month Number. Over in Power Pivot we have Sort and Filter, Sort by Column. I click on that and say sort the Month Name column by the Month Number. Click OK. When I Alt+Tab, you can see January to December with no problem.
Now watch this. If I drag Revenue down here, I get nothing but the total. That's the overall total. We still have at least one more step. We're going to have to go to the Diagram View, because this table is not communicating with the Revenue table. We need these dates connected to the fact table, so anytime it sees 1/3/2015 in our Revenue table, it knows to put it under January 2015. You have to go to Diagram View and create a relationship. This is a type of VLOOKUP connecting the two tables. Here's our fact table with all the transactions. Here's our calendar table. Click Date in the calendar table. Notice there's a unique list in that date column, one day for each day in the time period. I drag it over and drop, and just like that we get a relationship. Now when we go back to Data View, nothing happens there, but when we Alt+Tab back to our PivotTable, instantly we get what we want.
Now we need to drag Year above Month. We still have one more thing: the formatting. I want it to show up automatically, so I'm going to come over to the Revenue column, click the dropdown for English (United States) or whatever currency, and that formatting will flow through to the PivotTable, which doesn't happen in Excel. Just like that. I'll double-click and call this Power Pivot PT, come over, right-click, and delete that sheet. Now I want to do one last thing. Notice that Month Number and even this Date field I want to hide from this PivotTable field list. You'd rather have them pull from the calendar table than the Revenue table, and I don't want that one at all. So Alt+Tab, come over to Month Number, right-click, and hide from client tools. It looks gray here. Let's go to Revenue, right-click, and hide from client tools. This is just making it easy on the end user. Alt+Tab, and now we have no date here and no Month Number here. Absolutely awesome.
In Power Pivot it is quite a few more steps to group by month and year. If you're just going to group by month and year flat out, use Excel. If you have big data, half a million, a million, five million, ten million rows, then you have to start using Power Pivot, or you're going to build a bunch of formulas using DAX. Or if you have multiple sources of data that refresh often, you have to use Power Pivot. All right, we'll see you next trick.
