Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
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

247

 

 

Gotcha: Any subsequent use of the Advanced Filter command during this Excel session will remember the list range you specified in the Advanced Filter dialog box.

USE ADVANCED FILTER

Problem: What is the advanced filter used for?

Strategy: As the AutoFilter Filter gets more features, there are less times that you need to switch over to the Advanced Filter. There are still a few tasks that might be easier with the Advanced Filter.

The Advanced Filter can be used to filter to a subset of columns and/or to re-order columns. In the previous example, you filtered to a single column of customer. When you use the Copy To Another Location option and put headings in the Copy To range, you are specifying which columns and the order of the columns.

In the next three figures, you will see the List range, the Criteria range, and the Copy To range of a filter designed to produce a report for General Motors.

The List range contains seven fields:

Figure 626 The original input range.

The Criteria range in this case is two cells, specifying one customer.

3

Figure 627 One heading from the List range and the customer.

The Copy To range contains three fields in a new sequence.

Figure 628 Specify the fields to be returned.

Select one cell in the input range and choose Advanced Filter. Select Copy To Another Location. Fill in the three ranges. Do not check the Unique Values Only box.

Figure 629 Filter three columns for one customer.

The result is a new report with three columns of purchases by one customer.

248

POWER EXCEL WITH MR EXCEL

 

 

You can use Advanced Filter to create some unusual criteria ranges where the criteria are joined by a logical OR. Say that you were looking for custom- ers in the Transportation market or and custom- ers who purchased product S109. Set up a criteria range with each criterion on a different row.

Figure 630 These criteria are joined by an OR.

You will get records that match either criterion.

Figure 631 Records that match either criterion.

Criteria entered on the same row are joined by AND. In this example, you are looking for records where a Transportation customer purchased S102, or where a Retail customer purchased S109, or where a Financial customer purchased S108, or the purchase of S110 by any industry.

Figure 632 Filter will return customers who entirely match one row here.

Figure 633 Results of the filter.

Additional Details: To clear the advanced filter and show all the rows again, choose Data, Clear.

Several versions ago, you were not able to specify a Copy To range on a different worksheet than the List range. This limitation has been lifted.

REPLACE MULTIPLE FILTER CRITERIA WITH A SINGLE ROW OF FORMULAS

Problem: The Advanced Filter feature can handle combinations of criteria, but I have a particular situation where I want all records where the customer, industry and product come from these lists. To list all combinations of five products, five customers, and three indus- tries would require 75 rows of combinations. Is there an easier way?

Strategy: You can replace traditional criteria with a formula-based criteria range. To use a formula-based condition, leave the heading row of the criteria range blank. Write a logical formula in the criteria range that tests the first row of the data set. This formula will be ap- plied to all rows of the data set.

Figure 634 Get all combinations of these three lists.

PART 3: WRANGLING DATA

249

 

 

In the following example, the MATCH looks at the first product in cell C2 and sees if it is in the list of products in

M2:M6. Because match returns either the matching row number or an #N/A! error, the formula tests for #N/A! and then reverses the result using NOT. =NOT(ISNA(MATCH (C2,$M$8:$M$10,0))).

Similar formulas in I2 and J2 test for customers and in- dustries.

I2: =NOT(ISNA(MATCH(B2,M2:M6,0))) J2: =NOT(ISNA(MATCH(E2,$N$2:$N$6,0)))

Figure 635 Heading row blank, formula in row 2.

When you perform the Advanced Filter, specify I1:K2 as the criteria range. Excel will apply the formulas to each row of your dataset and only return the records where all three formulas evaluate to TRUE.

ADD SUBTOTALS TO A DATA SET

Problem: I have a lengthy report with invoice detail by customer. I need to add a subtotal at each change in customer.

Strategy: You can use the Subtotal feature to solve this problem in seconds instead of minutes. 1. Sort the data by customer.

2. Select a single cell in the data set. Then select Data, Subtotal. As shown below, the Subtotal dialog assumes that you want to subtotal by the field in the leftmost column of your data. It also assumes that you want to total the rightmost field.

3

Figure 636 The defaults in the Subtotal dialog are usually wrong.

3. Open the At Each Change In dropdown and choose Customer.

4. The Use Function dropdown in this case is already Sum. If your data set has a text column as the right-most column, this will say Count. Change it back to Sum.

5. Checkmark any numeric fields that should have a subtotal. In this case, Quantity, Revenue, and COGS. Profit is already checked because it is the right-most field.

6. If you want every customer on their own page, use Page Break Between Groups, although I am not selecting that option in this case.

250

POWER EXCEL WITH MR EXCEL

 

 

Figure 637 Subtotal at each change in customer.

7. Click OK. Excel will insert subtotals at each change in customer.

Figure 638 In seconds, Excel will insert new rows with subtotals.

If you scroll to the end of the data set, you will notice that Excel added a grand total of all customers. The inserted rows use the relatively new SUBTOTAL function. This function will total all the cells in the range except for cells that contain other SUBTOTAL functions.

Figure 639 Excel adds a grand total at the very bottom.

Additional Details: In order to remove subtotals, you select a cell in the data set and then select Data,

Subtotal. In the Subtotal dialog, you click the Remove All button.

Gotcha: This example works because the data was sorted by customer. If the data were sorted by invoice number instead, the result would be fairly meaningless.