谷歌表周/年数组公式

时间:2021-05-27 13:30:51

标签: google-sheets charts array-formulas

我有 sheet1 看起来像这样:

enter image description here

sheet2 看起来像这样:

ColA: =UNIQUE(ARRAY_CONSTRAIN({"周/年";arrayformula(IF(ISBLANK(Sheet1!A$2:A);"";CONCAT(CONCAT(WEEKNUM(Sheet1!A$2:A;2);"/"); TEXT(Sheet1!A$2:A;"YY"))))};COUNTA(Sheet1!A$2:A);1))

ColB: =SUM(FILTER(Sheet1!B$2:B; ARRAYFORMULA(WEEKNUM(Sheet1!A$2:A;2)=index(SPLIT(A2;"/");0;1)))) <--我需要帮助

enter image description here

图表是在sheet2的基础上构建的:

enter image description here

如果周数和年份与 A 列相同(A 列是日期格式 dd.mm.yyyy),我需要从 B 列获取值的总和。我设法按周数过滤了金额,但我无法为这一年添加第二张支票。请帮助我,我已经尝试了一切。

工作表示例: https://docs.google.com/spreadsheets/d/1XjJLOC5NHZwKirxbxZQzPAzpU8nCvhNs2_M323rZf3U/edit?usp=sharing

1 个答案:

答案 0 :(得分:2)

这是您需要的吗(单元格 A1)?删除列 B 中的值。

=arrayformula(query(query({Sheet1!A:B\if(Sheet1!A:A<>"";{weeknum(Sheet1!A:A;2)&"/"&right(year(Sheet1!A:A);2)\year(Sheet1!A:A)&"-"&text(weeknum(Sheet1!A:A;2);"00")};)};"select Col4,Col3,sum(Col2) where Col3 is not null group by Col4,Col3 label Col3 'Date', sum(Col2) 'Value' ";1);"select Col2,Col3";1))

注意事项:

我使用数组 {} 获得以下 4 列:

Col1 和 Col2:Sheet1!A:B

Col3:weeknum(Sheet1!A:A;2)&"/"&right(year(Sheet1!A:A);2)(例如 n/yy)

Col4:year(Sheet1!A:A)&"-"&text(weeknum(Sheet1!A:A;2);"00")(例如 yyyy-nn)

Col3 和 Col4 只返回一个值,而 A 列下有值:if(Sheet1!A:A<>"";

Col3 是图表中显示的周数和年份。

Col4 相同,但排序的格式不同。

第一个 query 得到 Col4,Col3 和 Col2 的和,然后第二个查询得到 Col3 和 sum(Col2)。

enter image description here