Google Sheets Formula: Sum if Substring in range of cells

∥☆過路亽.° 提交于 2021-02-05 06:37:06

问题


I have two columns:

Col A                    Col B
01.02.2020               17
03.11.2020               24
03.11.2020               12

I tried to sum Col B, based on the substring of Col A like so:

=SUMIF(A:A,MID(A:A,4,2)="02",B:B)
=SUMIF(A:A,MID(A:A,4,2)="11",B:B)

Which means: If it's the second (XX.02.XXXX) month, it should sum the values from Col B based on that. If it's the 11th month (XX.11.XXXX) in Col A, it should do the same but for cells where Col A has 11.

However, it doesn't work. Apparently, one cannot do the MID function over more than one cell?


回答1:


You need to use ARRAYFORMULA for that.

This one will give a column of sums for every month there is:

=ARRAYFORMULA(
  SUMIF(
    MID(A:A, 4, 2),
    UNIQUE(MID(FILTER(A:A, A:A <> ""), 4, 2)),
    B:B
  )
)

And if you have those dates formatted as date, having the type date, then you can use MONTH instead of MID to get the month number:

=ARRAYFORMULA(
  SUMIF(
    MONTH(F:F),
    UNIQUE(MONTH(FILTER(F:F, F:F <> ""))),
    G:G
  )
)



来源:https://stackoverflow.com/questions/60956211/google-sheets-formula-sum-if-substring-in-range-of-cells

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!