[英]Arrayformula for total in simple cashbook
I'm trying to create a simple arrayformula
to keep a running tally in a cashbook.我正在尝试创建一个简单的
arrayformula
来保持现金簿中的运行记录。 Pretty simple but got me stumped.很简单,但让我难住了。 Heres a basic table:
这是一个基本表:
A![]() |
B![]() |
C ![]() |
|
---|---|---|---|
1 ![]() |
IN![]() |
OUT![]() |
TOTAL![]() |
2 ![]() |
|||
3 ![]() |
10 ![]() |
10 ![]() |
|
4 ![]() |
1 ![]() |
9 ![]() |
|
5 ![]() |
7 ![]() |
16 ![]() |
|
6 ![]() |
5 ![]() |
21 ![]() |
|
7 ![]() |
4 ![]() |
17 ![]() |
So for example to generate the total in Cell C3 I use the formula offset(C3,-1,0)-B3+A3
but I thought I would then just be able to wrap it in arrayformula
so it became arrayformula(offset(C3:C,-1,0)-B3:B+A3:A)
but it errors and needs an extra row which just goes on endlessly.因此,例如要在单元格 C3 中生成总数,我使用公式
offset(C3,-1,0)-B3+A3
但我想我可以将它包装在arrayformula
中,所以它变成arrayformula(offset(C3:C,-1,0)-B3:B+A3:A)
但它会出错并且需要一个额外的行,这会无休止地进行。
Any help would be great.任何帮助都会很棒。
Use two running totals: of IN
and OUT
and subtract OUT
from IN
使用两个运行总计:
IN
和OUT
并从IN
中减去OUT
Classic arrayformula solution to create a running total is to use SUMIF with a variable string(relative to the range
argument) as a criterion
创建运行总计的经典数组公式解决方案是使用带有可变字符串(相对于
range
参数)的 SUMIF 作为criterion
=ARRAYFORMULA(SUMIF(ROW(A2:A7),"<="&ROW(A2:A7),A2:A7)-SUMIF(ROW(A2:A7),"<="&ROW(A2:A7),B2:B7))
Open range version:开放范围版本:
=ARRAY_CONSTRAIN(ARRAYFORMULA(SUMIF(ROW(A2:A),"<="&ROW(A2:A),A2:A)-SUMIF(ROW(A2:A),"<="&ROW(A2:A),B2:B)),ARRAYFORMULA(LOOKUP(2,1/(A2:A<>""),ROW(A2:A))),1)
use:利用:
=ARRAYFORMULA(IF((A2:A<>"")+(B2:B<>""),
MMULT(TRANSPOSE((ROW(B2:B)<=
TRANSPOSE(ROW(B2:B)))*IF(A2:A="", -B2:B, A2:A)),
SIGN(IF(A2:A="", -B2:B, A2:A))^0), ))
or:或者:
=ARRAYFORMULA(IF((A2:A<>"")+(B2:B<>""),
MMULT(TRANSPOSE((ROW(B2:B)<=TRANSPOSE(ROW(B2:B)))*
IF(A2:A="", A2:A-B2:B, A2:A-B2:B)),
SIGN(IF(A2:A="", B2:B, A2:A))^0), ))
=ARRAYFORMULA(IF(A2:A="",,MMULT(
TRANSPOSE((ROW(INDIRECT("2:"&MAX((A2:A<>"")*ROW(A2:A))))<=
TRANSPOSE( ROW(INDIRECT("2:"&MAX((A2:A<>"")*ROW(A2:A))))))*
(INDIRECT("C2:C"&MAX((A2:A<>"")*ROW(A2:A)))-
INDIRECT("D2:D"&MAX((A2:A<>"")*ROW(A2:A))))),
SEQUENCE(MAX((A2:A<>"")*ROW(A2:A))-1)^0)))
Thanks guys.多谢你们。 I tried @player0 method and got an error about array to big.
我尝试了@player0 方法并得到一个关于数组变大的错误。 And for some reason @TheMaster version just got stuck on the progress bar.
出于某种原因,@TheMaster 版本卡在了进度条上。 Anyway found this over on the google help forum
无论如何在谷歌帮助论坛上找到了这个
=ArrayFormula(if(len(A4:A),(SUMIF(ROW(D4:D),"<="&ROW(D4:D),D4:D)+SUMIF(ROW(C4:C),"<="&ROW(C4:C),C4:C)),))
And seems to work (I have a date in A4:A now).并且似乎有效(我现在在 A4:A 中有一个约会)。 But please let me know if you can see any potential issues
但是,如果您发现任何潜在问题,请告诉我
Update: I see that the answer I've adapted from @MattKing, is very similar to @TheMaster's earlier answer, just a variation on how we force the arrayformula to cycle through the cells.更新:我看到我从@MattKing 改编的答案与@TheMaster 早期的答案非常相似,只是我们如何强制arrayformula 循环通过单元格的一种变化。
Answer: In addition to player0's solution, I found a related question (where player0 also had the answer,).答:除了player0的解决方案,我发现了一个相关的问题(其中player0也有答案)。 and adapted a formula answer by @MattKing.
并改编了@MattKing 的公式答案。 Try the following in C1.
在 C1 中尝试以下操作。
={"Total";
ARRAYFORMULA(SUMIF(SEQUENCE(ROWS(A2:A),1),"<="&SEQUENCE(ROWS(A2:A),1,1,1),A2:A) -
SUMIF(SEQUENCE(ROWS(B2:B),1),"<="&SEQUENCE(ROWS(B2:B),1,1,1),B2:B) )}
Since it was originally designed to sum multiple columns, I'm not sure if I've reduced it as much as might be possible, for your single column implementation.由于它最初设计为对多列求和,因此对于您的单列实现,我不确定我是否已尽可能地减少它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.