[英]How to use comma separated values in a cell, as parameters in formula (PivotTable specifically)?
I have a formula that pulls data from PivotTable and sums up according to ID: 我有一个公式,可以从数据透视表中提取数据并根据ID进行汇总:
=SUM(GETPIVOTDATA("Value",$A$3,"AccounID",{5637855, 6839652, 5839670}))
I would like to use the same formula but with a reference: 我想使用相同的公式,但带有参考:
=SUM(GETPIVOTDATA("Value",$A$3,"AccounID",A1))
When A1
is: 5637855
, 6839652
, 5839670
. 当A1
为: 5637855
, 6839652
, 5839670
。
In this case if there is one ID or 10 IDs - it will be the same formula and I can only add an ID in the cell A1. 在这种情况下,如果有一个ID或10个ID,它将是相同的公式,我只能在单元格A1中添加一个ID。
I am sure that it is possible somehow with Macro, but I want a simple way (since macros in my company are restricted). 我确信Macro可以通过某种方式实现,但是我想要一种简单的方法(因为我公司中的宏受到限制)。
I found a few workarounds with SUMPRODUCT
and range of cells, but this solution is not practical in my case. 我发现了SUMPRODUCT
和单元格范围的一些解决方法,但是这种解决方案对我而言并不实际。
Use this array formula 使用此数组公式
=SUM(IFERROR(GETPIVOTDATA("Value",$A$3,"AccounID",TRIM(MID(SUBSTITUTE($A$1,",",REPT(" ",99)),(ROW($A$1:INDEX(A:A,LEN($A$1)-LEN(SUBSTITUTE($A$1,",",""))+1))-1)*99+1,99))),0))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. 作为数组公式,退出编辑模式时,需要使用Ctrl-Shift-Enter而不是Enter进行确认。
All the A1
refer to the cell in which the string is found, EXCEPT the first one in the ROW argument. 所有A1
引用找到该字符串的单元格, 除了 ROW参数中的第一个单元格。 Leave that as A1
change all the others to the cell in which the string can be found. 将其保留为A1
将所有其他参数更改为可以在其中找到字符串的单元格。
Try this: 尝试这个:
Option2: 选项2:
if someone doesn't have the cell A1
restriction` 如果某人没有单元格A1
限制`
Create a table (use format as table) with the IDs
you want to sum: 使用您要求和的IDs
创建一个表(使用格式作为表):
[criteria]
| 5637855|
| 6839652|
| 5839670|
Then replace in your formula with the range from your table criteria
like: 然后在您的公式中替换表格criteria
的范围,例如:
=SUM(GETPIVOTDATA("Value",$D$1,"AccounID",Table1[criteria]))
and activate the formula as an array with Ctrl + Alt + Enter or Ctrl + Shift + Enter depending your Excel version. 并使用Ctrl + Alt + Enter或Ctrl + Shift + Enter激活公式作为数组,具体取决于您的Excel版本。
If you highlight Table1[criteria]
in the formula and press F9 you will see that the value it is getting is {5637855, 6839652, 5839670}
. 如果在公式中突出显示Table1[criteria]
并按F9,您将看到它得到的值为{5637855, 6839652, 5839670}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.