Welcome to Excel Magic Trick number 1,436. Hey, if you want to download this Excel file, either the start file or the finished file, so you can follow along, click on the link below the video. Hey, we've got to see a great trick in Excel 2016. We need to combine two big tables into one for a PivotTable report.
Now here's our problem. If I click on the top cell and press Control + Down Arrow, that's 900,000 rows. Control + Down Arrow again, and this is almost a million rows. I have two tables side by side, but I really want to combine them, or append the first table and then join this to the bottom, into a single table. Then I need to make a simple PivotTable report, just product totals.
We can't simply copy and paste, because it just won't fit on an Excel sheet. But we have Excel 2016, so on the Data ribbon tab, in the Get & Transform group, we can use the From Table button to import both of these into the Power Query Editor. Then we can use Get Data, Combine, and Append, a feature found there. But where are we going to put it? We can't put it in the sheet. We'll put it into the Data Model. I happen to have Power Pivot, which is the right version to go look at the Data Model, but every single version of Excel 2016 has that Data Model. The Data Model contains a behind-the-scenes columnar database, which can hold big data. Now, this is about 2 million records, and the columnar database will have no problem with that. In fact, it can hold up to 100 million rows.
All right, let's see how to do this. Both of these have already been converted to Excel Tables by clicking in a single cell and choosing Insert > Table, or using Control + T. We also went to Design and named each table: FSales2 and FSales1. Now we can click in a single cell and choose From Table/Range, which adds it to the editor. We can check to see if the data types are correct. I'm going to click this icon to change the data type to simply Date. This message is asking, "Hey, do you want to replace the step we already created?" Yes, I do. Text is fine, decimal is fine. Now I come up and choose Close & Load. Don't click the button; click the Close & Load drop-down and choose Close & Load To.
Now, in our Import Data dialog box, we want to check only this option, Only Create Connection. It will load it into the editor. I click OK. I can see there's a connection only here. Click in the second table, From Table icon, change the data type to Date, and Replace. The data types are fine. Close & Load, then Close & Load To, choose Only Create Connection, and click OK. We had to load them both up into the Query pane over here, so we can come up to Data, Combine Queries, and Append. Notice the icon, field names, and table. Then we're going to join another table to the bottom: Append Two Tables. Guess what, you could do this with three or more.
I'm going to start with FSales1 and FSales2. It doesn't matter which order. In fact, we have exactly the same field names and data in each column in each table, so this will work just fine. Click OK. Now I'm going to name this whatever you want. I named it All Together. There's the table, with only one step. Now I can Close & Load, then Close & Load To. This is actually the third query, and we're going to say Only Create Connection and add this to the Data Model.
When we check this, you can't go look at the data if you don't have the correct version with Power Pivot, but no problem, it's totally there, and we can access it using the Create PivotTable dialog box. I'm going to click OK. We can see over here it's loading the data. It's actually loading, and then it's going to create, in the columnar database, a very efficient database that stores a unique list for each one of these columns. Since the date only spans two years, if we had all of the days, that would be 730, so about 700 records here. We only have around 20 products, and this column has a bunch of sales, but each one of these will be stored as a unique list, so it's very efficient. The file size we get will be smaller than the original data stored in the Excel sheet. There we go, about 1.9 million records.
I would save this so we have the original data, because now I'm going to delete these tables. Click in the top cell, press Control + Asterisk on the number pad, and I'll use the keyboard shortcuts over here: Clear All, Alt + E + A. Come over here, Control + Asterisk, Alt + E + A. That clears everything: the formatting, the table, the data, and so on. Now I'm going to click over here, and before we create our PivotTable, I'm going to save. If we go look at the original file, it was 41 megabytes, and by loading it into the columnar database, it went down to 9 megabytes.
Now we can create our PivotTable: Insert > PivotTable, or use the keyboard, Alt + N + V. Look at that, it's polite. It assumes, since we have data in the Data Model, that we want to use that. If it didn't, you would select that existing sheet, which is fine. Click OK. There's our All Together data. I can simply drag Product down to Rows and Sales over to Values. Right-click, Number Formatting, Currency, and click OK. Now, if we actually had the Data Model, we wouldn't drag Sales down here; we'd go create a measure over in the Data Model. But look at what we did: we took two huge tables that we didn't know what to do with, because we wanted to make a PivotTable. We used Power Query to append them, put the result in the Data Model, opened up a PivotTable connected to that Data Model, and there's our PivotTable.
All right, that's a little fun with two big tables for a PivotTable. We'll see you in the next video.
