简体   繁体   English

如何在单元格中使用逗号分隔的值作为公式中的参数(特别是数据透视表)?

[英]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为: 563785568396525839670

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 + EnterCtrl + 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.

相关问题 使用单个单元格的逗号分隔值作为数组公式的输入 - Use comma separated value of a single cell as input for array formula 逗号分隔值的查找公式 - Excel - lookup formula for comma separated Values- Excel Excel 转换逗号分隔列值的公式 - Excel Formula to convert comma separated column values 如何在Excel中的相同/单个单元格中将逗号分隔的值替换为逗号分隔的ID? - How to replace comma separated values to comma separated ids in the same/individual cell in excel? 如何用逗号分隔的值将数千个列合并到单个单元格中 - How to combine thousands of columns into a single cell with comma separated values 如何计算逗号,另一个单元格Excel中的所有列中的分隔值? - How To Count comma, another cell Separated Values In all Column In Excel? 如何匹配逗号分隔的单元格以求和多行的值? - How to match a comma separated cell to sum values from multiple rows? excel-如何在Excel中将单元格值转换为逗号分隔值? - How to convert the cell values in comma separated value in excel? 如何使用Java在CSV的一次单元格中添加逗号分隔的值 - How to add a comma separated values in once cell in CSV with java Excel公式来检查一个单元格中的逗号分隔列表中的项是否存在于另一单元格中的逗号分隔列表中? - Excel formula to check if items from a comma separated list in one cell exist in a comma separated list in another cell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM