简体   繁体   English

具有3个或更多多个数组条件的求和

[英]sumifs with 3 or more multiple array criteria

I have a SUMIFS that works off values contained in drop-downs and check boxes. 我有一个SUMIFS ,可以处理下拉列表和复选框中包含的值。 The values in the drop-downs work as AND criteria (ie sum a column conditional on this value in the drop down AND that value in the drop down), but things get tricky when I want to include the values in the check boxes, which are dynamic based on user entry. 下拉列表中的值用作AND准则(即,以下拉列表中的该值与下拉列表中的该值为条件的列求和),但是当我想在复选框中包括这些值时,事情变得棘手根据用户输入是动态的。 Essentially the values in the check box need to work as OR criteria (ie sum a column based on this value if box 1 is selected OR that value if box 2 is selected, also conditional on the values in the drop-down). 本质上,复选框中的值需要用作OR条件(即,如果选择了框1,则基于该值对一列求和;如果选择了框2,则以该值为基础,也以下拉菜单中的值为条件)。

Examples online show you can achieve a sumifs with OR criteria by doing the following: 在线示例显示,通过执行以下操作,您可以使用OR条件获得总和:

{=SUM(SUMIFS(sumrange,
    criteriarange0,"x",
    criteriarange1,{"1","2","3"},
    criteriarange2,{"A";"B"}
))}

where 哪里
"x" is the value in drop-down, "x"是下拉菜单中的值,
{"1","2","3"} are the resulting values if the three corresponding check boxes are ticked, {"1","2","3"}是在三个对应的复选框中打勾的结果值,
{"A";"B"} are another set of resulting values if their linked check boxes are ticked. 如果勾选了它们的链接复选框,则{"A";"B"}是另一组结果值。
1,2,3,A,B are all Boolean, in that they can change from the value to 0 if the check box is not ticked (so there are a matrix of combinations). 1,2,3,A,B均为布尔值,因为如果未选中复选框,则它们可以从值更改为0(因此存在组合矩阵)。

My question is how do you do this with 3 or more multiple arrays that act as OR conditions, which are quoted in the formula as cell references? 我的问题是,如何使用3个或多个作为OR条件的多个数组来执行此操作,这些数组在公式中被引用为单元格引用? Something like this: 像这样:

{=SUM(SUMIFS(sumrange, 
    criteriarange0,"x", 
    criteriarange1,value_range1, 
    criteriarange2,value_range2, 
    criteriarange3,value_range3
))}

I've found something involving SUMPRODUCT and ISNUMBER(MATCH() formulae, but can't get it to work. Additionally the table is 500,000 rows x 100 columns, so the formula needs to be efficient. 我发现了涉及SUMPRODUCTISNUMBER(MATCH()公式的东西,但无法使其正常工作,此外该表是500,000行x 100列,因此该公式需要有效。

Here is the crude formula I currently have with annotations: 这是我目前带有注释的原始公式:

={SUM(

SUMIFS(sumrange,$A:$A, $A1, $B:$B, $B1, $C:$C, $C1...,  

'sum a range conditional on the values in cells $A1, $B1, $C1. 求和一个范围,该范围取决于单元格$ A1,$ B1,$ C1中的值。 These are AND criteria. 这些是AND条件。

$E:$E,$AA10:$AC10, 

'include the dynamic values in $AA10:$AC10, which have the values: 5 years, 10 years, 15 years. '在$ AA10:$ AC10中包含动态值,这些值的值分别为:5年,10年,15年。 These are OR criteria. 这些是OR条件。

$F:$F,{$AA11;$AC11}, 

'also include these dynamic values for a different cell range: "5 days, 10 days, 15 days". ”还包括针对不同单元格范围的这些动态值:“ 5天,10天,15天”。 These are OR criteria. 这些是OR条件。

$G:$G,{$AA12;$AJ12})
)} 

'as well as include these multiple dynamic values, which are also OR criteria: "5 apples, 10 pears, 15 bananas". 并包括这些多个动态值,这些值也是OR标准:“ 5个苹果,10个梨,15个香蕉”。

Any combination of the dynamic values can be chosen. 可以选择动态值的任何组合。

You can sum the totals produced by two individual SUMIFS representing the last criteria. 您可以对两个代表最后一个标准的SUMIFS产生的总数求和。

=SUM(SUM(SUMIFS(A:A, B:B, "x", C:C, {1,2,3}, D:D, "a")), 
     SUM(SUMIFS(A:A, B:B, "x", C:C, {1,2,3}, D:D, "b")))

The last two criteria cannot be used in the same layout as the second criteria. 最后两个条件不能与第二个条件在同一布局中使用。 This produces confusion and miscalculation during the array's cyclic calculation. 这会在数组的循环计算过程中产生混乱和错误的计算。 However, if you can have the last criteria thought of as being in a different layout as the second criteria the calculation cycles should produce the correct result. 但是,如果您可以认为最后一个条件与第二个条件位于不同的布局中,则计算周期应会产生正确的结果。 TRANSPOSE will change the 'direction' of the last criteria array, thus changing the way it is calculated. TRANSPOSE将更改最后一个条件数组的“方向”,从而更改其计算方式。

=SUM(SUMIFS(A:A, B:B, "x", C:C, {1,2,3}, D:D, TRANSPOSE({"a","b"})))

This produces the same result¹ as the first formula. 这将产生与第一个公式相同的结果¹。

To add a third array of OR-based criteria, you would need to combine the two methods. 要添加第三组基于OR的条件,您需要将两种方法结合起来。

=SUM(SUM(SUMIFS(A:A, B:B, "x", C:C, {1,2,3}, D:D, TRANSPOSE({"a","b"}), E:E, "m")),
     SUM(SUMIFS(A:A, B:B, "x", C:C, {1,2,3}, D:D, TRANSPOSE({"a","b"}), E:E, "n")),
     SUM(SUMIFS(A:A, B:B, "x", C:C, {1,2,3}, D:D, TRANSPOSE({"a","b"}), E:E, "o")))

¹ Sample data: ¹ 样本数据:
Column A filled with random numbers. 列A充满随机数。
Column B filled with =CHAR(RANDBETWEEN(87, 89)) B列中填充= CHAR(RANDBETWEEN(87,89))
Column C filled with =RANDBETWEEN(0, 5) C列中填充= RANDBETWEEN(0,5)
Column D filled with =CHAR(RANDBETWEEN(65, 67)) D列中填充= CHAR(RANDBETWEEN(65,67))

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

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