在数组上使用 OR 逻辑作为 Sumproduct 中的参数 [英] Using OR logic on an array as argument in Sumproduct

查看:14
本文介绍了在数组上使用 OR 逻辑作为 Sumproduct 中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当大的数据集,我需要将多个条目组合成一个值.我的数据集包含两个数据集组合的数据,每个数据集都使用自己的 ID 和密钥.

I'm having a fairly large dataset where I need to combine multiple entries into a single value. My dataset contains data on the combination of two datasets, each using their own ID's and keys.

我想过像这样使用 Sumproduct() 函数:

I thought of using a Sumproduct() function like this:

=SUMPRODUCT(--('原始数据'!C:C=Landgebruik!A2);--('原始数据'!O:O={20;21;22;23;40});'原始数据'!S:S)

使用 Landgebruik!A2 保存第一个数据集的 ID,我需要将第二个数据集聚合到该 ID.

With Landgebruik!A2 holding an ID for the first dataset, which I need to aggregate the second dataset to.

'Raw data'!O:O 包含来自第二个数据集的 ID.在上述情况下,当第二个 ID 的值是以下任一值时,我需要对面积求和(在 'Raw data'!S:S 中):{20;21;22;23;40}.(OR 逻辑)该列仅包含整数值.

'Raw data'!O:O contains the ID's from the second dataset. In the case above I need to sum the area (in 'Raw data'!S:S) when the value of the second ID is any of these values: {20;21;22;23;40}. (OR logic) The column only contains integer values.

有没有其他方法可以解决这个问题,然后为数组中的所有值复制 --('Raw data'!O:O=20) ?

Is there any other way of fixing this then duplicating --('Raw data'!O:O=20) for all values in the array?

我现在采用了解决方法,即: =SUMPRODUCT(--('Raw data'!C:C=Landgebruik!A2);--('Raw data'!O:O=20)+('原始数据'!O:O=20)+('原始数据'!O:O=21)+('原始数据'!O:O=22)+('原始数据'!O:O=23)+('原始数据'!O:O=40);'原始数据'!S:S).但我觉得应该有更优雅的方式来做到这一点.

I went with the work-around for now, which was: =SUMPRODUCT(--('Raw data'!C:C=Landgebruik!A2);--('Raw data'!O:O=20)+('Raw data'!O:O=20)+('Raw data'!O:O=21)+('Raw data'!O:O=22)+('Raw data'!O:O=23)+('Raw data'!O:O=40);'Raw data'!S:S). But I feel that there should be a more elegant way of doing this.

推荐答案

你可以对你当前的公式做一个小小的改变;将 ; 更改为 *(在这种情况下也不需要 --):

You could make a small change to your current formula; change the ; to * (-- are also unneeded in that particular case):

=SUMPRODUCT(('Raw data'!C:C=Landgebruik!A2)*('Raw data'!O:O={20;21;22;23;40})*'Raw data'!S:S)

这应该有效.

当您将单独的参数提供给 SUMPRODUCT 时,每个参数必须具有相同的大小.但是当你像这样将它们相乘时,它会强制计算并且数组扩展.

When you feed separate parameters to SUMPRODUCT, each parameter has to be of the same size. But when you multiply them like this, it forces evaluation and the arrays expand.

例如,如果你有两个数组,5x1 和 1x5,你会得到一个 5x5 的结果数组:

For example, if you take two arrays, 5x1 and 1x5, you get a 5x5 resulting array:

这篇关于在数组上使用 OR 逻辑作为 Sumproduct 中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆