【问题标题】:How to split a google sheet range into parts by sum如何按总和将谷歌工作表范围分成几部分
【发布时间】:2020-06-08 18:18:46
【问题描述】:

我有一个三栏表:Name(ID)、Length(时间跨度)、Category(任意,可以是序列)。我想用值自动填充Category 列,以便每个类别的Length 列的总和相同。目前,我正在使用从this site 复制的公式=TRANSPOSE(SPLIT(JOIN(",", ARRAYFORMULA(REPT(G2:G9&",", H2))), ",")) 均匀拆分类别列。由于Length 列变化很大,因此我得到的类别大小差异很大。

这是我工作表中的示例数据:

Chapter       Length    Due Date (Category)
Chapter 2     00:23:43  07/06/2020
Chapter 3     00:19:01  07/06/2020
Chapter 4     00:13:29  07/06/2020
Chapter 5     00:13:00  07/06/2020
Chapter 6     00:07:56  07/06/2020
Chapter 7     00:12:38  08/06/2020
Chapter 8     00:15:20  08/06/2020
Chapter 9     00:23:51  08/06/2020
Chapter 10    00:29:40  08/06/2020
Chapter 11    00:23:37  08/06/2020
Chapter 12    00:15:39  09/06/2020
Chapter 13    00:27:07  09/06/2020
Chapter 14    00:09:18  09/06/2020
Chapter 15    00:21:52  09/06/2020
Chapter 16    00:31:35  09/06/2020
Chapter 17    00:21:17  10/06/2020
Chapter 18    00:57:07  10/06/2020
Chapter 19    00:24:42  10/06/2020
Chapter 20    00:20:24  10/06/2020
Chapter 21    00:32:28  10/06/2020
Chapter 22    00:35:17  11/06/2020
Chapter 23    00:25:54  11/06/2020
Chapter 24    00:26:35  11/06/2020
Chapter 25    00:21:25  11/06/2020
Chapter 26    00:37:04  11/06/2020
Chapter 27    00:24:27  12/06/2020
Chapter 28    00:05:15  12/06/2020
Chapter 29    00:07:29  12/06/2020
Chapter 30    00:41:52  12/06/2020
Chapter 31    00:43:30  12/06/2020
Chapter 32    00:34:31  13/06/2020
Chapter 33    00:45:24  13/06/2020
Chapter 34    00:20:02  13/06/2020
Chapter 35    00:14:43  13/06/2020
Chapter 36    00:23:56  13/06/2020

这是查询 =QUERY(A2:D56,"select D, count(D),sum(C) where D is not null group by D") 的结果,它按类别(到期日期)分组并打印时间总和:

Due Date     sum 
07/06/2020   1:17:09
08/06/2020   1:45:06
09/06/2020   1:45:31
10/06/2020   2:35:58
11/06/2020   2:26:15
12/06/2020   2:02:33
13/06/2020   2:18:36

我希望这张表的总和尽可能多,如下所示:

Due Date     sum 
07/06/2020   ~2:01:35
08/06/2020   ~2:01:35
09/06/2020   ~2:01:35
10/06/2020   ~2:01:35
11/06/2020   ~2:01:35
12/06/2020   ~2:01:35
13/06/2020   ~2:01:35

【问题讨论】:

    标签: google-sheets google-sheets-formula


    【解决方案1】:

    您也许可以对此进行改进,但作为第一次削减,我只需将累积经过的时间除以每天的平均时间(您发现大约 2 小时),然后用它来查找相应的日期:

    =ArrayFormula(to_date(vlookup(sumif(row(B2:B36),"<="&row(B2:B36),B2:B36)/(sum(B2:B36)/countunique(C2:C36)),
    {sequence(countunique(C2:C36),1,0),unique(C2:C36)},2)))
    

    我已将累计经过的时间放在日期旁边,这样您就可以看到每天的时间分配得有多好(或多坏):

    英国风格的日期稍微弄乱了我的格式,这很讽刺,因为我在英国,但我的工作表默认为美国:-(

    编辑

    我认为您可以通过将每章平均时间的一半添加到查找中来提高契合度:

    =ArrayFormula(to_date(vlookup((sumif(row(B2:B36),"<="&row(B2:B36),B2:B36)+average(B2:B36)/2)/(sum(B2:B36)/countunique(C2:C36)),
    {sequence(countunique(C2:C36),1,0),unique(C2:C36)},2)))
    

    如果您愿意,可以使用全列范围:

    =ArrayFormula(filter(to_date(vlookup((sumif(row(B2:B),"<="&row(B2:B),B2:B)+average(B2:B)/2)/(sum(B2:B)/countunique(C2:C)),
    {sequence(countunique(C2:C),1,0),unique(filter(C2:C,C2:C<>""))},2)),A2:A<>""))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多