数据透视表 筛选

When you create a pivot table in Excel, it doesn't matter if there are filters applied in the source data table. The pivot table includes all the data, whether it's hidden or not. But, if you'd like to create a pivot table from filtered list visible rows only, you can try this technique.

在Excel中创建数据透视表时,源数据表中是否应用了筛选器都没有关系。 数据透视表包括所有数据,无论是否隐藏。 但是,如果您只想从过滤后的列表可见行创建数据透视表,则可以尝试此技术。

Excel版本 (Excel Versions)

This technique uses new features in Excel, that are found in Excel for Office 365. Be sure that your version of Excel has the new functions, such as SORT and UNIQUE. I don't want you to waste your time trying something that won't work for you!

此技术使用Excel for Office 365中提供的Excel中的新功能。请确保您的Excel版本具有新功能,例如SORT和UNIQUE。 我不想让您浪费时间尝试对您不起作用的事情!

To check for the new functions:

要检查新功能:

  • Select a blank cell, then type: =SO

    选择一个空白单元格,然后键入: = SO

  • If the screen tip shows SORT and SORTBY, you have the new functions.如果屏幕提示显示SORT和SORTBY,则您具有新功能。

命名Excel表 (Named Excel Table)

In this example, the source data that we want to use for the pivot table is a named Excel table -- Sales_Data.

在此示例中,我们要用于数据透视表的源数据是一个命名的Excel表 -Sales_Data。

There are 100 records in the table, and it's currently filtered to show 2 of the sales rep names (Smith and Riaz), and all of the categories except Cookies.

该表中有100条记录,目前已对其进行过滤以显示2个销售代表名称(Smith和Riaz),以及除Cookie以外的所有类别。

NOTE: If your pivot table source data has a huge number of records, the following technique could slow down your workbook

注意 :如果您的数据透视表源数据具有大量的记录,以下技术可能会减慢您的工作簿

制作数据透视表 (Make a Pivot Table)

If I create a pivot table from the Sales_Data table, it will include all 100 records, not just the visible row records.

如果我从Sales_Data表创建数据透视表,它将包含所有100条记录,而不仅仅是可见的行记录。

All the sales rep names are listed, and all the categories are included.

列出所有销售代表名称,并包括所有类别。

来自筛选清单的枢纽 (Pivot From Filtered List)

To create a pivot table from filtered list visible rows only, I'll do these steps:

要仅从过滤列表可见行创建数据透视表,我将执行以下步骤:

  • Add a new column in the Sales_Data table.在Sales_Data表中添加一个新列。
  • In that column, use a formula to mark the visible rows在该列中,使用公式标记可见行
  • On another sheet, get the source data headings在另一张纸上,获取源数据标题
  • Use a new function to pull visible rows from the Sales_Data table使用新功能从Sales_Data表中提取可见行
  • Create a dynamic named range, based on pulled data and headings根据提取的数据和标题创建一个动态的命名范围
  • Create a pivot table based on the dynamic named range根据动态命名范围创建数据透视表

标记可见行 (Mark the Visible Rows)

The first step is to add a new column in the Sales_Data table, to mark the visible rows, using the SUBTOTAL function.

第一步是使用SUBTOTAL函数在Sales_Data表中添加新列,以标记可见行。

  • In cell J3, type the heading – Vis

    在单元格J3中,键入标题– Vis

  • In cell J4, start this SUBTOTAL formula, with 2 (Count) as the function number:在单元格J4中,以2(Count)作为函数编号开始此SUBTOTAL公式:
  • =SUBTOTAL(2,

    = SUBTOTAL(2,

  • Then, click on cell I4, which has the number of Orders, and type a closing bracket.然后,单击具有订单数量的单元格I4,然后键入一个右括号。
  • =SUBTOTAL(2,[@Orders])

    = SUBTOTAL(2,[@ Orders])

  • Press Enter, to add the formula to all the cells in the Vis column (even the hidden rows)按Enter键,将公式添加到“可见”列中的所有单元格(即使是隐藏的行)

这个怎么运作 (How It Works)

All the visible rows show 1 as the formula result in column J.

在J列中,所有可见行均将公式结果显示为1。

But, if you use formulas to do a COUNT and a SUM for column J, you'll see that the numbers are different.

但是,如果您使用公式对J列进行COUNT和SUM运算,则会看到数字不同。

There are 100 numbers in column J, but only 24 of those numbers are a 1.

J列中有100个数字,但其中只有24个数字是1。

The SUBTOTAL function ignores values that are hidden by a filter (and manually hidden rows, in some cases), so for non-visible rows, the result in column J is zero. For example:

SUBTOTAL函数将忽略由过滤器隐藏的值( 在某些情况下为手动隐藏的行 ),因此对于不可见的行,J列中的结果为零。 例如:

  • row 18 is visible, so it returns a 1第18行可见,因此返回1
  • row 19, is hidden by the filter, so it returns a zero第19行被过滤器隐藏,因此返回零

开始新工作表 (Start a New Sheet)

We'll create a new worksheet, and build a new source for the pivot table there.

我们将创建一个新的工作表,并在那里为数据透视表构建一个新的源。

  • Insert a new worksheet插入一个新的工作表
  • Name the sheet – DataFiltered命名工作表– DataFiltered

To build a pivot table, the data needs headings, so we'll use the ones from the Sales_Data table.

要构建数据透视表,数据需要标题,因此我们将使用Sales_Data表中的标题。

  • In cell A1 on the new sheet, type an equal sign在新工作表的单元格A1中,键入一个等号
  • Go to the FoodSales sheet, and click on cell A3, which has the first heading cell in the Sales_Data table.转到FoodSales工作表,然后单击单元格A3,该单元格在Sales_Data表中具有第一个标题单元格。
  • Press Enter, to complete the formula按Enter键以完成公式

Next, follow these steps to get the rest of the headings

接下来,请按照以下步骤操作以获取其余标题

  • Select cell A1, which has the link to the first heading选择具有第一个标题链接的单元格A1
  • Point to the fill handle, at the bottom right corner of cell A1指向单元格A1右下角的填充手柄
  • Drag across to column J, to get the rest of the Sales_Data table headings拖到列J,以获取其余的Sales_Data表标题
  • (optional) Format the heading cells in bold font(可选)将标题单元格设置为粗体

获取过滤的数据 (Get the Filtered Data)

Next, we'll use a new Excel function  -- FILTER -- to pull the visible rows from the Sales_Data table

接下来,我们将使用新的Excel函数FILTER来从Sales_Data表中提取可见行

  • Select cell A2, and start the formula:选择单元格A2,然后启动公式:

=FILTER(

=过滤器(

The first argument is the array – what we want to filter.

第一个参数是数组 –我们要过滤的内容。

Type the name of the table that we want to filter – Sales_Data, then type a comma

键入我们要过滤的表的名称– Sales_Data,然后键入逗号

=FILTER(Sales_Data,

= FILTER(Sales_Data,

The next argument is include – our rule for which records to return in the results. We want the rows where there is a 1 in the Vis column.

下一个参数是include –我们的规则,即要在记录中返回结果。 我们希望Vis列中的行为1。

  • Go to the FoodSales sheet, and click at the top of the Vis column heading cell转到FoodSales工作表,然后单击“ Vis”列标题单元顶部的
  • The table name and column name are added to the formula表名和列名已添加到公式中

=FILTER(Sales_Data,Sales_Data[Vis]

= FILTER(Sales_Data, Sales_Data [Vis]

  • Type our rule for that column: =1

    输入该列的规则: = 1

=FILTER(Sales_Data,Sales_Data[Vis]=1

= FILTER(Sales_Data,Sales_Data [Vis] = 1

  • Type a closing bracket, then press Enter to complete the formula输入右括号,然后按Enter键以完成公式

动态过滤数据数组 (Dynamic Array of Filtered Data)

Even though you only entered the formula in cell A2, the formula results are in a dynamic array, that spills down and across, in as many cells as needed.

即使您仅在单元​​格A2中输入了公式,公式结果仍以动态数组的形式出现,并根据需要扩散到整个单元格中。

There is a thin blue border around the dynamic array

动态数组周围有一个细的蓝色边框

动态数组中的单元 (Cells in the Dynamic Array)

If you click in any cell in the dynamic array, other than cell A2,

如果您单击动态数组中除单元格A2以外的任何单元格,

  • you can see the formula in light grey font in the formula bar您可以在编辑栏中看到浅灰色字体的公式
  • you can't make any changes to the formula您不能对公式进行任何更改

If you select cell A2, where the formula was entered, you can edit the formula, as usual

如果选择输入公式的单元格A2,则可以照常编辑公式

创建动态命名范围 (Create a Dynamic Named Range)

Now that we have headings and filtered data, we'll create a dynamic named range to use as the pivot table's source data.

现在已经有了标题和过滤后的数据,我们将创建一个动态的命名范围,用作数据透视表的源数据。

To refer to a dynamic array in a formula, use the array's starting cell, followed by the spill operator – #

要在公式中引用动态数组,请使用数组的起始单元格,然后使用溢出运算符–

In this example, here's the dynamic array reference:

在此示例中,这是动态数组参考:

DataFiltered!$A$2#

$ A $ 2#

We'll use that reference in an OFFSET formula, to create the dynamic range:

我们将在OFFSET公式中使用该引用来创建动态范围:

  • On the Excel Ribbon, click the Formulas tab, then click the Define Name command在Excel功能区上,单击“公式”选项卡,然后单击“定义名称”命令
  • For the Name, type: PivotUse

    对于名称,键入: PivotUse

  • Leave the Scope as Workbook将范围保留为工作簿
  • In the Refers to box, enter this OFFSET formula:在“引用”框中,输入以下抵消公式:

=OFFSET(DataFiltered!$A$2#,-1,0, ROWS(DataFiltered!$A$2#)+1, COLUMNS(DataFiltered!$A$2#))

= OFFSET(DataFiltered!$ A $ 2#,-1,0,ROWS(DataFiltered!$ A $ 2#)+ 1,COLUMNS(DataFiltered!$ A $ 2#))

  • Click OK, to complete the name单击确定,完成名称

抵消公式如何工作 (How the OFFSET Formula Works)

The OFFSET function returns a range that:

OFFSET函数返回的范围是:

  • Starts at the dynamic array从动态数组开始
  • Goes up one row (-1)上移一列(-1)
  • Moves over 0 columns移动超过0列
  • Includes the number of rows in the dynamic array, plus 1 for the heading row包括动态数组中的行数,标题行另加1
  • Includes the number of columns in the dynamic array包括动态数组中的列数

If the filters on the Sales_Data table are changed, the number of rows in the dynamic array will change.

如果更改了Sales_Data表上的过滤器,则动态数组中的行数将更改。

Our dynamic named range, PivotUse, will adjust to those changes automatically

我们的动态命名范围PivotUse将自动适应这些更改

创建数据透视表 (Create the Pivot Table)

The final step is to create a pivot table, based on the dynamic named range.

最后一步是根据动态命名范围创建数据透视表。

  • Insert a new sheet, and name it PivotVis插入一个新的工作表,并将其命名为PivotVis
  • Select any cell on the new sheet选择新工作表上的任何单元格
  • On the Excel Ribbon, click the Insert tab在Excel功能区上,单击“插入”选项卡
  • Click the Pivot Table command单击数据透视表命令
  • In the Create PivotTable dialog box, click in the Table/Range box, and press the F3 key on your keyboard在“创建数据透视表”对话框中,单击“表/范围”框,然后按键盘上的F3键
  • In the Paste Name list, click on PivotUse, and click OK在“粘贴名称”列表中,单击“ PivotUse”,然后单击“确定”。
  • For the location, choose the PivotVis sheet对于位置,选择“ PivotVis”表
  • Click OK to create the pivot table.单击“确定”创建数据透视表。

将字段添加到数据透视表 (Add Fields to the Pivot Table)

Next, use the PivotTable Field List to add the fields that you want to show in the pivot table.

接下来,使用数据透视表字段列表添加要在数据透视表中显示的字段。

If you include the Rep and Category fields, you'll see that they only include the items from the visible rows in the Sales_Data table.

如果包含Rep和Category字段,您将看到它们仅包含Sales_Data表中可见行中的项目。

更改Sales_Data过滤器 (Change the Sales_Data Filters)

If you change the filters in the Sales_Data table, be sure to refresh the pivot table after you've finished making the changes.

如果更改Sales_Data表中的过滤器,请确保在完成更改后刷新数据透视表。

For example, filter the data so it only shows sales in the East region.

例如,过滤数据,使其仅显示东部地区的销售额。

The dynamic array updates automatically, and now there are only 14 rows on that sheet.

动态数组会自动更新,现在该工作表上只有14行。

However, pivot tables don't refresh automatically, so you can do that step manually.

但是,数据透视表不会自动刷新,因此您可以手动执行此步骤。

Right-click on the pivot table, and click Refresh.

右键单击数据透视表,然后单击刷新。

After the refresh, only the East region records are showing. Riaz didn't make any sales in that region, so Smith is the only rep in the filtered data, and in the refreshed pivot table.

刷新后,仅显示东部地区的记录。 Riaz在该地区没有任何销售,因此Smith是过滤后的数据以及刷新的数据透视表中的唯一代表。

获取样本文件 (Get the Sample File)

To see how the pivot table from filtered list visible rows technique works, go to the Pivot Table Source Data page on my Contextures site.

若要查看来自过滤列表可见行的数据透视表技术如何工作, 请转到 Contextures网站上的“ 数据透视表源数据”页面 。

In the Download section, get the Filtered Source Data sample file. The zipped file is in xlsx format, and does not contain any macros.

在“下载”部分中,获取“ 过滤的源数据”样本文件 。 压缩文件为xlsx格式,不包含任何宏。

翻译自: https://contexturesblog.com/archives/2020/03/05/pivot-table-from-filtered-list-visible-rows/

数据透视表 筛选


http://www.taodudu.cc/news/show-6741939.html

相关文章:

  • UITableView根据表格内容进行高度自适应与使用Masonry实现根据内容进行宽度自适应和高度自适应
  • 【开发记录】利用QT读取Excel并写入数据
  • 使用 FEDOT 自动化时间序列预测
  • poi 合并单元格添加边框_如何在Excel中的文本和单元格边框之间添加空间
  • 基于另一个单元格值的条件格式
  • Qt去掉最大化最小化按钮和最大化
  • MFC的最大化,最小化,关闭
  • 最大化,最小化的区别
  • 最大化与最小化
  • 能力最大化
  • 最大化
  • 最大化窗口
  • 【深度学习】什么是互信息最大化?
  • 最小化”“最大化”“关闭”
  • 窗口最大化
  • 激活最大化
  • 【日常笔记系列】在PostgreSQL中使用Dapper时不能使用in?
  • PG一些资料网站
  • PostgreSQL使用pgAdmin4不能编辑表里的数据
  • 【PostgreSQL】一些常见细节问题
  • PostgreSQL Huge Page使用最佳实践
  • pg修改表的owner
  • PG的状态有哪些
  • go-pg常用操作大全:你需要的都在这里!
  • PostgreSQL下pg_rewind的使用
  • 使用ChatGPT前应当学会提问
  • ceph PG和PGP调整经验
  • 一部分关于pg的小知识
  • 关于postgresql的种种恶心问题
  • 关于PostgreSQL使用的一些心得

数据透视表 筛选_筛选列表可见行中的数据透视表相关推荐

  1. redis 命令 数据清理_如何在命令行中清理数据

    redis 命令 数据清理 我是兼职数据审计师. 可以将我视为校对员,使用数据表而不是散文页面. 这些表是从关系数据库中导出的,通常大小适中:100,000至1,000,000条记录和50至200个字 ...

  2. 创建分区表+分区表的分类+创建散列分区表+查看散列分区表分区中的数据+创建列表分区表+查看列表分区表分区中的数据...

    创建分区表 分区表的分类 范围分区:对数据表的某个值的范围进行分区,需要使用partition by range字句. 散列分区: 1通过hash算法均匀分布数据的一种分区类型. 2通过在I/O设备上 ...

  3. mysql 一行数据长度限制吗_【MySQL】行长度的一些限制

    标签: 今天开发在导入数据的时候报一个错误: Row size too large. The maximum row size for the used table type, not countin ...

  4. Python基础_第5章_Python中的数据序列

    Python基础_第5章_Python中的数据序列 文章目录 Python基础_第5章_Python中的数据序列 Python中的数据序列 一.字典--Python中的==查询==神器 1.为什么需要 ...

  5. 删除html表里的数据,如何删除HTML表格行中表格数据之间的空白?

    我想弄清楚如何删除HTML表格中的表格数据之间的额外空间.例如,在下面的代码中,在我的Web浏览器IE中查看代码时,"名字"表格数据和"输入名称"表格数据之间会 ...

  6. easyexcel 读取指定行数据_Excel怎么设置只提取指定行中的数据?

    Excel怎么设置只提取指定行中的数据?有些时候我们需要从一个excel文件中的数据库中提取指定的行或列中的数据.例如如图示,是国内所有上市公司的行业统计.但是现在我们只需要其中部分上市公司的行业统计 ...

  7. unix和linux命令_Linux vs. Unix,在命令行中清理数据,为儿童准备的15本书,以及更多必读内容

    unix和linux命令 上周,关于Linux与Unix的一篇文章是最受欢迎的读物. 查看其他Opensource.com读者对以下内容的了解: Linux与Unix:有什么区别? ,作者:菲尔·埃斯 ...

  8. 将数据写入json文件,并且读取json文件中的数据

    目录 一.将数据生成json文件 二.读取json文件中的数据 三.方法测试 四.其他附件 1.User实体类 2.import 一.将数据生成json文件 方法 /*** 生成.json格式文件*/ ...

  9. [计算机组成原理] Cache 行长一般指 Cache 行中的数据部分的长度,Cache 容量一般指 Cache 数据部分的容量

    在组号映射的地方清楚地讲了 Cache 行中包含标记部分和有效位 同理,在 Cache 写策略处写了若采用回写法,Cache 行还包含一位脏位 由此看来 Cache 总容量 = 行数×行长 = 行数× ...

最新文章

  1. oracle中的exists 和 not exists 用法详解
  2. Generator-ing Values
  3. effective java英文版pdf_Java之Spring1:Spring简介、环境搭建、源码下载及导入MyEclipse...
  4. 经典案例鸢尾花分类, 在Keras中使用sklearn调参
  5. javascript 类继承
  6. 60-100-032-使用-MySQL大小写敏感的解决方法
  7. mycat核心配置详解(schema.xml配置)
  8. 这么多牛逼的Java常用Json库,万万没想到它的性能最好!
  9. 拓端tecdat|Python支持向量回归SVR拟合、预测回归数据和可视化准确性检查实例
  10. 顶顶顶!! Xcode7.1下用CocoaPods安装Alamofire--swift下的第三方网络库
  11. 二进制转换八进制图解_二进制如何转换成八进制?
  12. python接入讯代理_[Python3网络爬虫开发实战] 9.3-付费讯代理、阿布云代理的使用...
  13. 愿天下有情人都是失散多年的兄妹(bfs)
  14. 网络安全篇 防火墙的静态路由-04
  15. 苍蓝誓约服务器一直维护,《苍蓝誓约》11月26日09:30停服维护公告
  16. python格式化字符串固定宽度_python – 格式化固定宽度的字符串(unicode和utf8)
  17. 【哈士奇赠书活动 - 23期】-〖你好 ChatGPT〗
  18. 华为系统更新彻底卸载_华为手机系统更新好吗 华为手机系统更新方法
  19. 爱普生LQ-635K针式打印机打链式打印纸设置自动切纸方法
  20. ExcelDNA的入门使用

热门文章

  1. 飞康恢复oracle
  2. 我跟大牛的一段谈话、没有什么特别的意思、只是想给想我一样刚进入工作的大学生一点启迪
  3. 机器学习的核心概念置信度和置信区间,我用这个例子把它讲明白
  4. Centos7与Windows安装JDK8及环境变量配置(附安装包)
  5. 【转载】2020年中国乘用车前视系统TOP10供应商,本土仅经纬恒润入围!
  6. 511遇见易语言读入文件和写到文件
  7. HDU 4417-Super Mario-线段树+离线
  8. 科丁乐编程LV4第一单元考试题目与讲解
  9. 开源门户网站Liferay Portal
  10. 从零基础学PS平面设计入门到精通是…