【问题标题】:Rolling count with array formula in Google SheetsGoogle表格中使用数组公式的滚动计数
【发布时间】:2020-04-26 14:22:33
【问题描述】:

我有下面的数据集。 Col1 是给定数据,Col2 是 Col1 前 5 行(含)的滚动计数。

Date      Col1  Col2
01/04/20  2     1
02/04/20  1     2 
03/04/20  4     3
04/04/20        3
05/04/20        3
06/04/20  5     3
07/04/20  2     3
08/04/20        2
09/04/20        2
10/04/20  1     3
11/04/20        2
12/04/20        1
13/04/20        1
14/04/20        1
15/04/20  1     1

有没有办法使用 arrayformula 来做到这一点,而不是在 Col2 的每个单元格中输入一个计数公式?

【问题讨论】:

    标签: google-sheets count array-formulas


    【解决方案1】:

    您可以在行上使用带有条件的 Countifs:

    =ArrayFormula(filter(countifs(B2:B,">0",row(B2:B),"<="&row(B2:B),row(B2:B),">"&row(B2:B)-5),A2:A<>""))
    

    假设数字是正数

    要包含任何数字,您可以使用:

    =ArrayFormula(filter(countifs(isnumber(B2:B),true,row(B2:B),"<="&row(B2:B),row(B2:B),">"&row(B2:B)-5),A2:A<>""))
    

    如果您想将未来日期对应的行显示为空白,您可以添加一个 If 语句:

    =ArrayFormula(filter(if(A2:A>today(),"",countifs(isnumber(B2:B),true,row(B2:B),"<="&row(B2:B),row(B2:B),">"&row(B2:B)-5)),A2:A<>""))
    

    【讨论】:

    • 非常感谢!如果连续的相应日期大于今天,是否可以编辑公式以使输出为空白?
    • 是的,将其添加到我的答案中
    • 非常感谢。如果您能提供帮助,我对 sum 有一个非常相似的问题? stackoverflow.com/questions/61452819/…
    • 啊,这可能更困难,因为 SUMIFS 不适用于数组,但可以看看。
    猜你喜欢
    • 2020-08-10
    • 2018-01-15
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 2020-06-04
    • 2020-03-22
    • 2020-09-07
    • 1970-01-01
    相关资源
    最近更新 更多