Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Power excel 2016 with mrexcel Master Pivot Tables, Subtotals, Charts, VLOOKUP, IF, Data Analysis in Excel 2010–2013 (Bill Jelen) (z-lib.org).pdf
Скачиваний:
4
Добавлен:
14.08.2022
Размер:
49.75 Mб
Скачать

PART 3: WRANGLING DATA

 

371

 

 

 

FILL IN BLANKS WITH VALUES FROM ABOVE

Problem: In the previous figure, I need to fill in all the blank cells.

Strategy: In Power Query, select the column. Use Transform, Replace Values. Leave the Value to Find box blank and change Replace With to null. After the replace, you will see italicized null values right- aligned in the column. Use Transform, Fill, Down. Power Query will fill the nulls with the value above.

Figure 952 This is easier than Home, Find & Select, Go To Special, Blanks = Up Arrow Ctrl+Enter.

USE POWER QUERY TO CLEAN DATA ALREADY IN EXCEL

Problem: My data is already in Excel. I need to transform the data. I need to unpivot the month data.

3

Figure 953 Unpivot this data.

Power Query can either read from a named range or a range that has been Formatted as a Table using

Ctrl+T.

Follow these steps:

1. Select one cell inside your data set.

2. First, convert your data set to a table using Ctrl+T. 3. Choose Power Query, From Table.

4. In the Query Editor, click on the Jan heading to select that column.

5. Shift+Click on the Dec column to select all the columns between Jan and Dec. 6. On the Transform tab, select Unpivot Columns.

7. Optionally, rename the Attribute column to be Month.

8. On the Home tab, choose Close and Load.

You will see a new worksheet with the results.

Figure 954 If the underlying data changes, you can refresh this query.

372

POWER EXCEL WITH MR EXCEL

 

 

 

PIVOT FROM MULTIPLE TABLES IN EXCEL 2013 DATA MODEL

Problem: I have a lot of rows in a data table and then some lookup tables. Is there a faster way to create a report than building a bunch of VLOOKUP formulas?

Strategy: Excel 2013 adds a pivot table feature called the Data Model. This will solve the problem. This will work in all versions of Excel 2013, whether you have the Power Pivot tab installed or not.

The process works much better if you declare all of your data sets to be Ctrl+T tables first.

1. Select one cell in your main data set and press Ctrl+T. Confirm that the data has headers and click

OK.

2. In the Table Tools Design tab, you will see a name for the table. Type a meaningful name, something like Data.

3. Select one cell in your lookup data. Ctrl+T. OK. Rename this table Sectors. 4. Go back to the original data. Select one cell. Insert, Pivot Table.

5. In the Create Pivot Table dialog, check the box for Add This Data to the Data Model. Click OK.

Figure 955 Checking this box opens a wide variety of new options.

It seems like a really innocuous box, but by checking that box in Excel 2013, you are loading the data into the Power Pivot data model that is hidden behind Excel 2013. If this is the first time you’ve used the Data

Model in this Excel session, you might notice a few-second delay before you get to the Pivot Table Field list.

At this point, everything feels like a regular pivot table with one small change. You will notice a line at the top of the Pivot Table Field List offering ACTIVE | ALL.

Figure 956 Before you move on to All, create a relationship.

6. Go to the Analyze tab in the ribbon. Choose Relationships. Click New...

7. There are four fields to fill out in the Create Relationship dialog. Start from your Data table and choose the key field used to link to the lookup table. For the Related table, choose the lookup table and the key field. Click OK.

Figure 957 This is far easier than a VLOOKUP.

8. You can now go to the ALL section of the Pivot Table Fields.

9. You can now expand each table and choose fields from that table.

PART 3: WRANGLING DATA

373

 

 

Figure 958 Choose fields from any table.

The result is a pivot table with fields from Sheet1 and Sheet2.

Figure 959 The data model is an amazing improvement.

Joining two tables in a pivot table is an amazing improvement. Although Excel calls this the Data Model,

it is really the Power Pivot Engine. Even if you don’t have two tables to join, there are some interesting 3 reasons to run the data through the Data Model. See January Actuals and February Plan later in this chapter.

REPORTING FROM THE SMALLER SIDE OF THE RELATIONSHIP

Problem: I am trying to report sales and quota. My sales table has hundreds of records. The Quota table has just one record per region. The pivot table created through the Data Model is not working.

Strategy: In the data below, both column C and Column E were originally called Region. For this exam- ple, those fields have been named differently, The relationship is between Region_S and Region_Q.

Figure 960 The table on the left is hundreds of records.

If you use Region_S in the pivot table, the Quota numbers will be incorrect. Change the pivot table to use Region_Q from the Quota table and they will be correct.

374

POWER EXCEL WITH MR EXCEL

 

 

Figure 961 The report will be correct or not depending on which Region you use.

I have to admit, as someone who formerly dabbled in Access, I expected a wrong answer in the top example. But I would have expected the Central region quota of $300,000 multiplied by the 213 records for the Central region, producing $63,900,000.

USE JOINER TABLES BETWEEN TABLES

Problem: I have a top-level budget table with one row per month, region, product. It has 54 rows. I want to create a report comparing the budget table to an invoice table with hundreds of rows.

Strategy: Create three tiny “joiner” tables to act as intermediaries between the two tables. In the figure below, the three row Product table is a joiner table. Build a relationship from ProductB in the Budget table to Product_J in the joiner table. Build a second relationship from ProductA in the Invoice table to Product_J in the joiner table. Build similar relationships, joining Region_J to both RegionB and RegionA.

Also create relationships to join the Date field to both DateB and DateA.

Figure 962 Add extra tables to act as intermediaries between Budget and Invoice Detail.

When you build your pivot table, all fields in the Rows, Columns, and Slicers should come from the Joiner table.