Google Sheet arrayformula 引用同一列的前一行:错误循环引用

时间:2021-05-21 11:26:48

标签: google-sheets google-sheets-formula

尝试创建引用前一行的数组公式。 不断收到#REF 错误:

Circular dependency detected. To resolve with iterative calculation, see File > Spreadsheet Settings.

看到很多其他帖子有类似的问题,但似乎没有一个为我解决。

用户在 A 列中输入详细信息,B 列应显示开始/忙碌/结束。例如

|A              | B            |
|---------------|------------- |
|[heading A]    | [heading B]  |
|start          | start        |
|something      | busy         |
|something else | busy         |
|end            | end          |
|something      |              |
|something else |              |
|start          | start        |
|something      | busy         |
|end            | end          |
|start          | start        |
|end            | end          |
|...            | ...          |

在B2中试过,得到循环引用错误:

=arrayformula(if((A2:A="start")+(A2:A="end"),A2:A, if((A1:A="start")+(B1:B="busy"),"busy","") ))

=arrayformula(if((A2:A="start")+(A2:A="end"),A2:A, if((A1:A="start")+(offset(B2:B,-1,0)="busy"),"busy","") ))

此行在开始行之后的第一行显示 busy(因为 A1:A="start" 测试),但不显示其他“繁忙”行(因此:indirect("B"&row(B2:B)-1)="busy" 测试不工作)。

=arrayformula(if((A2:A="start")+(A2:A="end"),A2:A, if((A1:A="start")+(indirect("B"&row(B2:B)-1)="busy"),"busy","") ))

对于那个,当我用 "" 替换 "B"&row(B2:B)-1 时,它会按照我的预期显示间接单元格引用,例如在 B4 中显示“B3”。

建议如何使用数组公式填充开始/忙碌/结束值?

1 个答案:

答案 0 :(得分:2)

在单元格 B1 中试试这个:

=arrayformula({"[Heading B]";if(A2:A="start","start",if(A2:A="end","end",if(COUNTIFS(A2:A,"start",ROW(A2:A),"<="&ROW(A2:A))=COUNTIFS(A2:A,"end",ROW(A2:A),"<="&ROW(A2:A)),,"busy")))})

enter image description here

注意事项:

我检查以下条件:

A) 单词 'start' 的序列

=arrayformula(if(A2:A<>"",COUNTIFS(A2:A,"start",ROW(A2:A),"<="&ROW(A2:A)),))

B) 单词“end”的序列:

=arrayformula(if(A2:A<>"",COUNTIFS(A2:A,"end",ROW(A2:A),"<="&ROW(A2:A)),))

C) 每一行的 A) 和 B) 是否相同。在它们相同的情况下,该项目要么是结束'开始'的'结束',要么是我们需要忽略的'其他东西'。

COUNTIFS(A2:A,"start",ROW(A2:A),"<="&ROW(A2:A)) = COUNTIFS(A2:A,"end",ROW(A2:A),"<="&ROW(A2:A))

D) 最终逻辑在“结束”之后识别“其他事物”并将其忽略:

=arrayformula(if(A2:A="start","start",if(A2:A="end","end",if(xxx,,"busy")))) 其中 xxx 是上面的 C) 项是否为真。

enter image description here