A

问题描述 投票:0回答:1

给定一个这样的表。

    + ------ + ------- + ---------- + ---------- + ---------- + ---------- +
    |    A   |    B    |      C     |      D     |      E     |      F     |
    + -------+ ------- + ---------- + ---------- + ---------- + ---------- +
    |  AVG   |  ITEMS  | Week 3 May | Week 2 May | Week 1 May | Week 5 Apr |
    |=QUERY()|  Item 1 |    1263    |    1255    |    1142    |     956    |
    |        |  Item 2 |    1371    |    1263    |    1023    |    1120    |
    |        |  Item 3 |    1382    |    1257    |    1352    |    1853    |
    |        |  Item 4 |    1429    |    1281    |    1120    |    1869    |
  1. 我需要把B列移到第一列(A)。

  2. 制作一个脚本,为新条目添加一个新的colum。


1.-

在AVG列(上面的例子中的A列)有一个使用公式的平均值。

=QUERY(transpose(query(transpose(B2:$F),"Select "&REGEXREPLACE(join("",ArrayFormula(if(len(B2:B),"Avg(Col"&ROW($C2:$C)-ROW($C2)+1&"),",""))), ".\z","")&"")),"Select Col2")

This formula calculates the average of the last 4 weeks only if there's an entry in column B

我需要将这一列移动到项目列表(B列)的右边,但是当我尝试这样做时,公式显示出循环依赖错误。有没有办法告诉公式只选取我想要的列?

2.-

还有一个按钮,有一个指定的宏,使新的列在左边的 最新 周为新条目,并插入周号和月份,这就是脚本。

  function onEdit() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('C:C').activate();
  spreadsheet.getActiveSheet().insertColumnsBefore(spreadsheet.getActiveRange().getColumn(), 1);
  spreadsheet.getActiveRange().offset(0, 0, spreadsheet.getActiveRange().getNumRows(), 1).activate();
  spreadsheet.getRange('C1').activate()
  .setFormula('=CONCATENATE("Week ",(WEEKNUM(TODAY(),2)-WEEKNUM(EOMONTH(TODAY(),-1)+1)+1)," ",CHOOSE(MONTH(TODAY()),"Jan","Feb","Mar","Apr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dec"))');
};

所以它变成了这样的东西。

    + ------ + ------- + ---------- + ---------- + ---------- + ---------- + ---------- +
    |    A   |    B    |      C     |      D     |      E     |      F     |      G     |
    + -------+ ------- + ---------- + ---------- + ---------- + ---------- + ---------- +
    |  AVG   |  ITEMS  | Week X MMM | Week 3 May | Week 2 May | Week 1 May | Week 5 Apr |
    |        |  Item 1 | (NEW WEEK) |    1263    |    1255    |    1142    |     956    |

而这是我用来计算周号的公式。

=CONCATENATE("Week ",(WEEKNUM(TODAY(),2)-WEEKNUM(EOMONTH(TODAY(),-1)+1)+1)," ",CHOOSE(MONTH(TODAY()),"Jan","Feb","Mar","Apr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dec"))

这个公式的问题在于它使用了TODAY()函数,它有一个变量,而我需要一个静态值。此外,在使用脚本时,条件格式化没有在新列中延续。我如何改进这个脚本?

google-sheets google-sheets-formula google-sheets-query google-sheets-macros
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.