使用工作表绘制图表的星期,月份汇总结果

时间:2018-03-22 20:18:05

标签: google-sheets spreadsheet google-sheets-query

有没有办法将每日价值转化为图表的每周平均值?

示例源表

---------------------------------------------------
| Data 1 | 1/1/2018 | 1/2/2018 | 1/3/2018 | etc...365 days |
---------------------------------------------------
| row 1  |    25    |   30     |    5     | etc...| 
---------------------------------------------------
| row 2  |    2     |          |    4     | etc...|
---------------------------------------------------
| etc ... each row has a different cadence.

除了每行,每行可能没有值,而是每周或每月,具体取决于节奏。所以我想使用查询函数将某些行聚合为星期,将某些行聚合为月份。

预期结果 对于每周聚合(如果有超过1个值我只想要一周的平均值,IE:如果在一周内有值:2,3,3,只显示:2)

---------------------------------------------------
| Data 1 | Week 1 | Week 2 | Week 3 | etc...52 weeks |
---------------------------------------------------
| row 1  |    25  |   30   |    5   | etc...| 
---------------------------------------------------
| row 2  |    2   |   0    |    4   | etc...|
---------------------------------------------------
| etc ... 

每月汇总(如果有超过1个值,我只想要当月的平均值,IE;如果在一个月内有值:25,50,100,只需显示:58)

---------------------------------------------------
| Data 1 | Jan | Feb | Mar | etc...12 months |
---------------------------------------------------
| row 1  | 50  | 30  |  55 | etc...| 
---------------------------------------------------
| row 2  | 2   |  0  | 4   | etc...|
---------------------------------------------------
| etc ...

这样,我可以创建显示正确度量单位(周,月等)的图表。我怎么能转换?

2 个答案:

答案 0 :(得分:0)

几个月:

function foo(event, url) { event = event || window.event; event.preventDefault(); swal({ title: 'Are you sure?', text: 'By clicking \'OK\' you will be redirected to the link.', icon: 'warning', buttons: { cancel: true, confirm: true } }).then(function(value) { if (value) { // Either true or null window.location.href = url; } }); }

=TRANSPOSE( QUERY( TRANSPOSE(Sheet1!A1:Y4), "select month(Col1) + 1, avg(Col" & JOIN("), avg(Col",ARRAYFORMULA(row(INDIRECT("a2:a"&COUNTA(Sheet1!A2:A)+1)))) & ") group by month(Col1) + 1") )部分将生成如下的查询字符串:

select

结果:

"select month(Col1) + 1, avg(Col2), avg(Col3), ... group by month(Col1) + 1"

答案 1 :(得分:0)

一周:

=ROUND(AVERAGE(ARRAYFORMULA(VALUE(QUERY(
 {ARRAYFORMULA(TRANSPOSE(WEEKNUM($A$1:$AE$1, 2))),
  TRANSPOSE($A2:$AE2)},
 "select Col2 where Col1 matches '"&COLUMN()&"'", 0)))), 0)

一个月:

=ROUND(AVERAGE(ARRAYFORMULA(VALUE(QUERY(
 {ARRAYFORMULA(TRANSPOSE(MONTH($A$1:$AE$1))),
  TRANSPOSE($A2:$AE2)},
 "select Col2 where Col1 matches '"&COLUMN()&"'", 0)))), 0)

3