按照Google表格中的WEEKNUM进行分组。

huangapple go评论108阅读模式
英文:

Group by WEEKNUM in google spreadsheet

问题

  1. 我使用查询来从列日期(J)中获取周数,并在这里汇总成本的公式如下:
  2. ```excel
  3. =QUERY(J4:K, "SELECT WEEKNUM(J), SUM(K) WHERE J IS NOT NULL GROUP BY WEEKNUM(J) LABEL WEEKNUM(J) 'Week', SUM(K) 'Total'")

我尝试使用MONTH而不是WEEKNUM,它完全正常运行,我真的不知道错误可能在哪里。

示例文件:https://docs.google.com/spreadsheets/d/1GO-BwaEWOSf1AnR7rKOMYcpZ_12crehiSJTkFVOOqx8/edit?usp=sharing

更新:
[2]: https://i.stack.imgur.com/w6Lhl.png

为什么会有间隙?

  1. <details>
  2. <summary>英文:</summary>
  3. I&#39;m using query for getting the weeknum from column Date (J) and sum the cost here is the formula

=QUERY(J4:K, "SELECT WEEKNUM(J), SUM(K) WHERE J IS NOT NULL GROUP BY WEEKNUM(J) LABEL WEEKNUM(J) 'Week', SUM(K) 'Total'")

  1. I tried using MONTH instead of WEEKNUM and it run perfectly, I really don&#39;t know where the error might be
  2. sample file : https://docs.google.com/spreadsheets/d/1GO-BwaEWOSf1AnR7rKOMYcpZ_12crehiSJTkFVOOqx8/edit?usp=sharing
  3. [![\[1\]: https://i.stack.imgur.com/0uYlr.png][1]][1]
  4. ________________________________________________________________
  5. update :
  6. [![enter image description here][2]][2]
  7. why there&#39;s a gap?
  8. [1]: https://i.stack.imgur.com/HfEcB.png
  9. [2]: https://i.stack.imgur.com/w6Lhl.png
  10. </details>
  11. # 答案1
  12. **得分**: 3
  13. `WEEKNUM` `QUERY` 中**不存在**
  14. 您可以尝试以下操作

=QUERY(INDEX(IF(A72:A86="",, {WEEKNUM(A72:A86),B72:C86})), "在此处使用 Col1,sum(Col3) 等编写您的查询")

  1. ## 编辑
  2. 刚刚检查了您的表格。
  3. 请在您的公式中尝试这个查询

=QUERY(INDEX(IF(A2:A22="",, {WEEKNUM(A2:A22),B2:C22})),
"选择 Col1,sum(Col2) where Col1 不为空
按 Col1 分组 标签 Col1 '周',sum(Col2) '周汇总' ")

  1. *(根据您的范围和地区* **自行调整** *公式)*
  2. <details>
  3. <summary>英文:</summary>
  4. `WEEKNUM` does **not exist in `QUERY`**
  5. Instead you can try the following
  6. =QUERY(INDEX(IF(A72:A86=&quot;&quot;,, {WEEKNUM(A72:A86),B72:C86})), &quot;your query here using Col1, sum(Col3) etc&quot;)
  7. ## EDIT
  8. Just checked your sheet.
  9. Try this query in your formula
  10. =QUERY(INDEX(IF(A2:A22=&quot;&quot;,, {WEEKNUM(A2:A22),B2:C22})),
  11. &quot;Select Col1, sum(Col2) where Col1 is not null
  12. group by Col1 label Col1 &#39;week&#39;, sum(Col2) &#39;sum/week&#39; &quot;)
  13. *(**Do** adjust the formulae according to your ranges and locale)*
  14. </details>
  15. # 答案2
  16. **得分**: 1
  17. `WEEKNUM()` 不被 `QUERY()` 识别为 SQL 函数。您可以尝试以下方式:
  18. ```excel
  19. =QUERY({INDEX(WEEKNUM(A2:INDEX(A2:A,COUNTA(A2:A))), B2:INDEX(B2:B,COUNTA(A2:A))}, "select Col1, sum(Col2) group by Col1 label Col1 'Week', sum(Col2) 'Sum'")

按照Google表格中的WEEKNUM进行分组。

英文:

WEEKNUM() is not recognized by QUERY() as SQL function. You may try-

  1. =QUERY({INDEX(WEEKNUM(A2:INDEX(A2:A,COUNTA(A2:A)))),B2:INDEX(B2:B,COUNTA(A2:A))},
  2. &quot;select Col1, sum(Col2) group by Col1 label Col1 &#39;Week&#39;, sum(Col2) &#39;Sum&#39;&quot;)

按照Google表格中的WEEKNUM进行分组。

答案3

得分: 1

这里有另一种方法 非查询型

  1. ={ "Week", "Sum" ; index( map( unique( weeknum( filter( A2:A, A2:A<>"" ) ) ), lambda( z, { z, sumif( weeknum( A:A ), z, B:B ) } ) ) ) }

按照Google表格中的WEEKNUM进行分组。

英文:

Here's another approach non-query based

  1. ={&quot;Week&quot;,&quot;Sum&quot;;index(map(unique(weeknum(filter(A2:A,A2:A&lt;&gt;&quot;&quot;))),lambda(z,{z,sumif(weeknum(A:A),z,B:B)})))}

按照Google表格中的WEEKNUM进行分组。

huangapple
  • 本文由 发表于 2023年3月9日 18:15:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75683187.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定