简体   繁体   English

我需要 ARRAYFORMULA() 来使用另一行中的条件来决定要计算的内容

[英]I need ARRAYFORMULA() to use conditions in another row to decide what to calculate

Here is my formula in G5 =ARRAYFORMULA(IF(AND(J5:J17=true,H5:H17=false),E5:E17*F5:F17*1.075,IF(AND(J5:J17=true,H5:H17=TRUE),0,IF(and(J5:J17=false,H5:H17=false),E5:E17*F5:F17,IF(and(J5:J17=false,H5:H17=true),0)))))这是我在 G5 中的公式=ARRAYFORMULA(IF(AND(J5:J17=true,H5:H17=false),E5:E17*F5:F17*1.075,IF(AND(J5:J17=true,H5:H17=TRUE),0,IF(and(J5:J17=false,H5:H17=false),E5:E17*F5:F17,IF(and(J5:J17=false,H5:H17=true),0)))))

This works if Cols H,I, and J are all false, however once I start setting anything in H,I,or J to true, the formula stops working.如果列 H、I 和 J 全部为假,则此方法有效,但是一旦我开始将 H、I 或 J 中的任何内容设置为真,公式就会停止工作。

在此处输入图像描述

在此处输入图像描述

Thanks for any help, Im really stumped on this one.感谢您的帮助,我真的被这个难住了。

I think you can simplify your formula all the way down to:认为您可以将公式一直简化为:

=arrayformula(E5:E17*F5:F17*not(H5:H17)*if(J5:J17,1.075,1))

A few pointers:几点建议:

  • What you were trying to achieve boils down to: 'on each row, give me the value of the cell in colE * the value of the cell in colF, multiplied by 1.075 if the cell in colJ is ticked, unless the cell in colH is ticked, in which case give me 0.您要实现的目标归结为:'在每一行上,给我 colE 中单元格的值 * colF 中单元格的值,如果勾选了 colJ 中的单元格,则乘以 1.075,除非 colH 中的单元格是勾选,在这种情况下给我 0。
  • You don't need to evaluate tickboxes against TRUE/FALSE as they contain a TRUE/FALSE themselves (so the =TRUEs & =FALSEs in your formula are redundant)您不需要根据 TRUE/FALSE 评估复选框,因为它们本身包含 TRUE/FALSE(因此公式中的 =TRUEs 和 =FALSEs 是多余的)
  • AND/OR in arrays don't work the way you might initially want them to as they are aggregating functions (ie they accept arrays as input by design) and wrapping them in ARRAYFORMULA to try to make them evaluate the input arrays row-by-row or column-by-column doesn't work. AND/OR 在 arrays 中并没有按照您最初希望的方式工作,因为它们正在聚合函数(即它们接受 arrays 作为设计输入)并将它们包装在 ARRAYFORMULA 中以尝试让它们逐行评估输入 arrays行或逐列不起作用。 Historically the answer to this problem has been to use Boolean algebra (where AND is * & OR is +, FALSE=0 and TRUE<>0) as I've done here which normally makes for the most compact representation, but more recently it's also been possible to use MAP to process arrays element-by-element (in which case AND/OR can still be used) as per one of the other answers从历史上看,这个问题的答案是使用 Boolean 代数(其中 AND 是 * & OR 是 +,FALSE=0 和 TRUE<>0),正如我在这里所做的那样,这通常是最紧凑的表示,但最近它是根据其他答案之一,也可以使用 MAP 逐个元素地处理 arrays(在这种情况下仍然可以使用 AND/OR)
  • You only really need to use IF statements if you want to return values other than TRUE/FALSE (1/0) as a result of a logical evaluation (like your colJ where you want TRUE=1.075 & FALSE=1);如果你想返回 TRUE/FALSE (1/0) 以外的值作为逻辑评估的结果(比如你想要 TRUE=1.075 & FALSE=1 的 colJ),你只需要真正使用 IF 语句; otherwise you can omit them and just use Booleans.否则你可以省略它们而只使用布尔值。

use:利用:

 =ARRAYFORMULA(IF((J5:J17=true)*(H5:H17=false), E5:E17*F5:F17*1.075,
  IF((J5:J17=true)*(H5:H17=TRUE), 0,
  IF((J5:J17=false)*(H5:H17=false), E5:E17*F5:F17,
  IF((J5:J17=false)*(H5:H17=true), 0)))))

You can try to do this with MAP:您可以尝试使用 MAP 进行此操作:

=MAP(J5:J17,H5:H17,E5:E17,F5:F17,LAMBDA(j,h,e,f,
IF(AND(j=true,h=false),e*f*1.075,IF(AND(j=true,h=TRUE),0,IF(and(j=false,h=false),e*f,IF(and(j=false,h=true),0))))))

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

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