简体   繁体   English

从扩展/折叠数据透视表中提取“隐藏”数据-Excel

[英]Extracting “hidden” data from expanding/collapsing pivot table - Excel

I'm not sure if this is possible but as you can see I have a pivot table with multiple dependent and expandable fields. 我不确定是否可行,但是如您所见,我有一个包含多个相关字段和可扩展字段的数据透视表。 I am trying to concatenate the data from columns A:D into one cell which works fine in row 2 but doesn't work with blank parent cells, as you can see in column F. 我正在尝试将A:D列中的数据连接到一个单元格中,该单元格在第2行中工作正常,但不适用于空白父单元格,如F列所示。

Any ideas for how to achieve this? 关于如何实现这一目标的任何想法?

Pivot table 数据透视表

数据透视表

This answer assumes that you don't want to just Repeat All Item Labels in the PivotTable from the "Report Layout" drop-down on the Pivt Table Tools "Design" tab. 此答案假定您不希望仅从数据透视表工具“设计”选项卡上的“报表布局”下拉列表中重复数据透视表中的所有项目标签。

A formula to get the first non-blank value on or above the same row as the current cell from Column B can be constructed with a combination of AGGREGATE , SUMPRODUCT and OFFSET , like so: 可以使用AGGREGATESUMPRODUCTOFFSET的组合构造一个公式,以获取与列B中的当前单元格相同或更高的行上的第一个非空白值,如下所示:

=OFFSET($B2,SUMPRODUCT(AGGREGATE(14,6,ROW($B$1:$B$100)*--(ROW($B$1:$B$100)<=ROW())*--(LEN($B$1:$B$100)>0),1))-ROW(),0)

How does it work? 它是如何工作的?

Starting with the outermost part, OFFSET($B2, VALUE, 0) - this will start in cell B2 , then look up or down by VALUE rows to get the value. 从最外面的部分OFFSET($B2, VALUE, 0)开始-这将从单元格B2开始,然后按VALUE行向上或向下查找以获取值。

Next we need to know how many rows we will need to look up-or-down. 接下来,我们需要知道向上或向下查找多少行。 Now, if we can work out the bottom-most row with data, we can subtract the current ROW() from that, giving us OFFSET($B2, NON_BLANK-ROW(),0) 现在,如果我们可以计算出数据的最底行,则可以从中减去当前的ROW() ,从而获得OFFSET($B2, NON_BLANK-ROW(),0)

So, to finish up we need to work out which rows are not blank, AND which rows are on-or-above our current row, then take the largest of those. 因此,要结束,我们需要找出哪些行不为空白,以及哪些行在当前行之上或之上,然后采用其中最大的一行。 This is going to take an ArrayFormula, but we can use SUMPRODUCT to make that calculate properly. 这将采用ArrayFormula,但是我们可以使用SUMPRODUCT进行正确的计算。 To find the largest number we could use MAX or LARGE - but we get less errors if we pick AGGREGATE(14,6,..,1) . 为了找到我们可以使用数量最多MAXLARGE -但我们得到更少的错误,如果我们选择AGGREGATE(14,6,..,1) (The 14 means "we want the k th largest number", the 6 means "ignore error values", and the 1 is k - so "we want the largest number, ignoring errors") 14表示“我们想要第k个最大数字”, 6表示“忽略错误值”,而1表示k-因此“我们想要最大的数字,忽略错误”)

But, what list of numbers are we going to look at, I don't hear you ask. 但是,我们要看什么数字列表,我没有听到您问。 Well, we want the ROW for output from our range (I'm using $B$1:$B$100 , because using the whole column B would take far to long to calculate repeatedly), a comparison against the current ROW() , and check that the LEN gth is > 0. Those last two are comparisons, so let's write them out first: 好吧,我们想要我们范围内的输出的ROW (我使用$B$1:$B$100 ,因为使用整个B列需要花费长时间才能重复计算),并与当前ROW()进行比较请检查LEN gth>0。最后两个是比较,因此我们首先将它们写出来:

ROW($B$1:$B100)<=ROW() 

and

LEN($B$1:$B$100)>0

We want to use -- to convert TRUE and FALSE to 1 and 0 - this means that any "bad" values become 0, and any "good" values are larger than 0: 我们要使用--TRUEFALSE转换为10这意味着任何“不良”值都将变为0,并且任何“良好”值都将大于0:

ROW($B$1:$B$100)*--(ROW($B$1:$B$100)<=ROW())*--(LEN($B$1:$B$100)>0)

This gives us the Row number when the Row is on-or-before the current row AND Column B is not blank - if either of those are False, then we get 0 instead. 当行位于当前行之前或之前且行B不为空时,这将为我们提供行号-如果其中任何一个为False,则取值为0。 Stick that in the AGGREGATE to find the largest number: 将其粘贴在AGGREGATE以找到最大的数字:

AGGREGATE(14, 6, ROW($B$1:$B$100)*--(ROW($B$1:$B$100)<=ROW())*--(LEN($B$1:$B$100)>0), 1)

Then put it in a SUMPRODUCT to force Excel to treat it as an ArrayFormula, and that's your NON_BLANK . 然后将其放在SUMPRODUCT以强制Excel将其视为ArrayFormula,这就是您的NON_BLANK This then gives you that first formula right at the top of the post 然后,您可以在帖子顶部找到第一个公式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM