Google Sheet formula for cumulative sum with condition

前端 未结 2 1917
庸人自扰
庸人自扰 2021-01-27 06:20

I have a Google Sheet with the following layout:

  Number |  Counted?  |  Cumulative Total
    4    |     Y      |         4
    2    |            |         6
           


        
相关标签:
2条回答
  • 2021-01-27 06:36

    Try this in C2 and copy down:

    = N(C1) + A2 * (B2 = "Y")
    

    Update

    Doesn't seem to work with SUMIFS, but there is a very slow matrix multiplication alternative:

    =ArrayFormula(MMult((Row(2:1000)>=Transpose(Row(2:1000)))*Transpose(A2:A1000*(B2:B1000="Y")), Row(2:1000)^0))
    
    0 讨论(0)
  • 2021-01-27 06:41

    Assuming "Number" in column A and "Counted?" in column B, try in C1

    ={"SUM"; ArrayFormula(if(ISBLANK(B2:B),,mmult(transpose(if(transpose(row(B2:B))>=row(B2:B), if(B2:B="Y", A2:A,0), 0)),row(B2:B)^0)))}
    

    (Change ranges to suit).

    Example

    0 讨论(0)
提交回复
热议问题