填充由日期周期定义的单元格

时间:2016-04-05 19:55:06

标签: date google-sheets populate

很抱歉,如果帖子实际上是重复的。只是无法谷歌任何类似的东西,我有点卡住方法。 我试图在一张纸上填充单元格,具体取决于不同纸张行中的日期,如下所示:

Sheet1 - 条目表

ID | Name | Start date | End date
10 | Mike | 1.06.2016  | 2.06.2016
13 | Dido | 1.06.2016  | 5.06.2016
8  | Rene | 2.06.2016  | 20.06.2016

Sheet2 - 报告表

 ids/dates  | 1.06.2016 | 2.06.2016 | 3.06.2016 | date+1
  8         |           | Rene      | Rene      | Rene 
 10         | Mike      | Mike      |           |
 13         | Dido      | Dido      | Dido      | Dido 

名称单元格将在sheet2中填充,具体取决于Sheet1列ID,开始日期,结束日期。填充单元格的位置在sheet2中按列ID和行日期定义,它们应与sheet1中的相同值相等。

1 个答案:

答案 0 :(得分:0)

这份报告可以借助一个公式来完成。请check this Example File

<强>假设

假设您有Sheet1包含数据:

  • Col A:ID
  • Col B:姓名
  • Col C:开始日期
  • Col D:结束日期

案例1. ID是唯一的。

转到Sheet2并将此公式粘贴到其中:

={{"ids/dates";filter(Sheet1!A2:A,Sheet1!A2:A<>"")},{ArrayFormula(add(MIN(Sheet1!C:D),COLUMN(OFFSET(A1,,,1,MAX(Sheet1!C:D)-MIN(Sheet1!C:D)))-1));ArrayFormula(if(--(add(MIN(Sheet1!C:D),COLUMN(OFFSET(A1,,,1,MAX(Sheet1!C:D)-MIN(Sheet1!C:D)))-1)>=filter(Sheet1!C2:C,Sheet1!C2:C<>0))*--(add(MIN(Sheet1!C:D),COLUMN(OFFSET(A1,,,1,MAX(Sheet1!C:D)-MIN(Sheet1!C:D)))-1)<=filter(Sheet1!D2:D,Sheet1!C2:C<>0))=1,VLOOKUP(FILTER(Sheet1!A2:A,Sheet1!A2:A<>""),Sheet1!A:B,2,0),""))}}

这就是全部。当新数据到达Sheet1时,报告将自动扩展。如果在Sheet1上数据未完成(错误的名称或日期),报告将返回错误。

案例2. ID不是唯一的。

当ID不唯一时,此解决方案有效,ID将组合在一起。在这种情况下,一个ID属于一个人。

公式会更长一些:

={{"ids/dates";sort(UNIQUE(filter(Sheet1!A2:A,Sheet1!A2:A<>"")))},{ArrayFormula(add(MIN(Sheet1!C:D),COLUMN(OFFSET(A1,,,1,MAX(Sheet1!C:D)-MIN(Sheet1!C:D)))-1));ArrayFormula(if(QUERY(QUERY({filter(Sheet1!A2:A,Sheet1!A2:A<>""),ArrayFormula((--(add(MIN(Sheet1!C:D),COLUMN(OFFSET(A1,,,1,MAX(Sheet1!C:D)-MIN(Sheet1!C:D)))-1)>=filter(Sheet1!C2:C,Sheet1!C2:C<>0))*--(add(MIN(Sheet1!C:D),COLUMN(OFFSET(A1,,,1,MAX(Sheet1!C:D)-MIN(Sheet1!C:D)))-1)<=filter(Sheet1!D2:D,Sheet1!C2:C<>0))))},"select Col1, sum(Col"&JOIN("), sum(Col",ArrayFormula(COLUMN(OFFSET(B2,,,1,MAX(Sheet1!C:D)-MIN(Sheet1!C:D)))))&") group by Col1"),"Select Col"&JOIN(", Col",ArrayFormula(COLUMN(OFFSET(B2,,,1,MAX(Sheet1!C:D)-MIN(Sheet1!C:D)))))&" where Col1>0",0)=1,VLOOKUP(sort(UNIQUE(filter(Sheet1!A2:A,Sheet1!A2:A<>""))),Sheet1!A:B,2,0),""))}}

请参阅example here.

案例3. ID不是唯一的。一个ID&lt;&gt;一个名字

这是working example,请检查一下。这个案子最难。我们可以有多个ID引用多个名称。最终公式:

={{"ids/dates",ArrayFormula(add(MIN(Sheet1!C:D),COLUMN(OFFSET(A1,,,1,MAX(Sheet1!C:D)-MIN(Sheet1!C:D)))-1))};{sort(UNIQUE(FILTER(Sheet1!A2:A,Sheet1!A2:A<>""))),ArrayFormula(IFERROR(VLOOKUP(QUERY(QUERY({FILTER(Sheet1!A2:B,Sheet1!A2:A<>""),ArrayFormula(--(add(MIN(Sheet1!C:D),COLUMN(OFFSET(A1,,,1,MAX(Sheet1!C:D)-MIN(Sheet1!C:D)))-1)>=filter(Sheet1!C2:C,Sheet1!C2:C<>0))*--(add(MIN(Sheet1!C:D),COLUMN(OFFSET(A1,,,1,MAX(Sheet1!C:D)-MIN(Sheet1!C:D)))-1)<=filter(Sheet1!D2:D,Sheet1!C2:C<>0))*row(OFFSET(A1,,,rows(FILTER(Sheet1!A2:B,Sheet1!A2:A<>"")))))},"select Col1, sum(Col"&JOIN("), sum(Col",ArrayFormula(COLUMN(OFFSET(C1,,,1,MAX(Sheet1!C:D)-MIN(Sheet1!C:D)))))&") group by Col1"),"Select Col"&JOIN(", Col",ArrayFormula(COLUMN(OFFSET(B2,,,1,MAX(Sheet1!C:D)-MIN(Sheet1!C:D)))))&" where Col1>0",0),{ArrayFormula(row(OFFSET(A1,,,rows(FILTER(Sheet1!A2:B,Sheet1!A2:A<>""))))),FILTER(Sheet1!A2:B,Sheet1!A2:A<>"")},3,0)))}}

如果两个日期范围相交,公式将无法正常工作:

102   Mike   6/21/2016  6/27/2016
102   Mike   6/11/2016  6/22/2016