简体   繁体   English

Google Sheets Query - 为没有记录数据的日期填充零

[英]Google Sheets Query - fill zeros for dates when no data was recorded

How do I change my query in this google sheet so that it generates a table that has a column for every week, even if there is no data for that week?我如何更改此 google 表格中的查询,以便它生成一个包含每周一列的表,即使该周没有数据? (display 0 in the values fields) (在值字段中显示 0)

The problem I'm running into is that if there is a week or date with no data, it's not listed.我遇到的问题是,如果有一周或日期没有数据,则不会列出。 I would like to generate a row/column with 0 for dates without data.我想为没有数据的日期生成一个带有 0 的行/列。

This is how the query is currently written:这是查询当前的编写方式:

=QUERY(A3:D9,"Select A, sum(C) group by A pivot D")

Here's the sheet (hyperlinked so you can see it):这是表格(超链接以便您可以看到它):

谷歌表

The basic problem you need to solve is to know which data pieces are missing.您需要解决的基本问题是知道哪些数据片段丢失了。 Do you need the entries for every single day in a given date range?您是否需要给定日期范围内每一天的条目? Only weekdays?只有工作日吗? Only weekdays, except public holidays?只有工作日,公共假期除外? etc.等等。

Once you know that, you can insert the missing data in the query itself, by concatenating the source table with literal data as below (where I'm manually adding a combination of Red with Nov 5), or with another query/resultset of another formula that gives you the missing data:知道这一点后,您可以通过将源表与文字数据连接如下(我手动添加 Red 与 11 月 5 日的组合)或与另一个查询/结果集在查询本身中插入缺失的数据为您提供缺失数据的公式:

=QUERY({A3:D9; {"Red", date(2018,11,5), 0, weeknum(date(2018,11,5))}},
       "Select Col1, sum(Col3) group by Col1 pivot Col4")

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM