Fill missing dates in Google Sheets

折月煮酒 提交于 2020-05-16 07:50:06

问题


I have two columns:

Col A                    Col B
01.02.2020               17
03.11.2020               24
03.11.2020               12

As I stated in another question, I tried to sum Col B, based on the month in Col A. The solution was the following formula (without the sort):

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

Something I missed was the population of missing months. Therefore my question is: How can I populate the result table with the missing months and zeroes until values are entered? The desired output for the table above would be:e

Col A                    Col B               Col C
01.02.2020               17                  0
03.11.2020               24                  17
14.12.2020               100                 0
03.11.2020               12                  0
                                             0
                                             0
                                             0
                                             0
                                             0
                                             0
                                             36
                                             100

回答1:


If just doing it for the current year, this should be enough

=ArrayFormula(sumif(mid(A2:A,4,2),sequence(12),B2:B))




回答2:


alternative:

=ARRAYFORMULA(IFNA(VLOOKUP(ROW(A1:A12), QUERY(A:B, 
 "select month(A),sum(B) group by month(A)"), 2, 0), 0))



来源:https://stackoverflow.com/questions/60976657/fill-missing-dates-in-google-sheets

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