使用Google表格查询功能对数据进行分组

时间:2019-10-17 23:26:09

标签: regex google-sheets google-sheets-formula array-formulas google-sheets-query

我在Google表格中有以下数据:

Data

我想在另一张表中运行查询功能,以便在选择日期后,查询将在单个列中返回在单个日期参加过事件的所有与会者,如下所示:

After Query

我的公式在每个日期下只能返回一名与会者,当时可能有50名员工参加一次活动。我希望所有50个都在一列中,而不是50个单独的列中。

下面是指向我的数据的链接。 “其他出勤”表的单元格D2是我的查询功能。

Data

不胜感激有关公式的帮助。

1 个答案:

答案 0 :(得分:1)

您可以执行以下操作:

=ARRAYFORMULA(TRANSPOSE({QUERY('Form Responses 4'!B:D,
 "select B,C 
  where C >= date '"&TEXT(B5, "yyyy-mm-dd")&"'
    and C <= date '"&TEXT(B6, "yyyy-mm-dd")&"' 
    and B = '"&B4&"' 
  order by C asc", 1), 
 REGEXREPLACE(SPLIT(QUERY('Form Responses 4'!B:D,
 "select D
  where C >= date '"&TEXT(B5, "yyyy-mm-dd")&"'
    and C <= date '"&TEXT(B6, "yyyy-mm-dd")&"' 
    and B = '"&B4&"' 
  order by C asc", 1), ";"), "^, ", )}))

0


=ARRAYFORMULA(TRANSPOSE({QUERY('Form Responses 4'!B:D,
 "select B,C 
  where C >= date '"&TEXT(B5, "yyyy-mm-dd")&"'
    and C <= date '"&TEXT(B6, "yyyy-mm-dd")&"' 
    and B = '"&B4&"'"&
    IF(B3<>"all", "and D contains '"&B3&"'", )&" 
  order by C asc", 1), 
 REGEXREPLACE(SPLIT(QUERY('Form Responses 4'!B:D,
 "select D
  where C >= date '"&TEXT(B5, "yyyy-mm-dd")&"'
    and C <= date '"&TEXT(B6, "yyyy-mm-dd")&"' 
    and B = '"&B4&"'"&
    IF(B3<>"all", "and D contains '"&B3&"'", )&" 
  order by C asc", 1), ";"), "^, ", )}))

0


=ARRAYFORMULA(TRANSPOSE({QUERY('Form Responses 4'!B:D,
 "select B,C 
  where C >= date '"&TEXT(B5, "yyyy-mm-dd")&"'
    and C <= date '"&TEXT(B6, "yyyy-mm-dd")&"'"& 
    IF(B4<>"all", "and B = '"&B4&"'", )&
    IF(B3<>"all", "and D contains '"&B3&"'", )&" 
  order by C asc", 1), 
 REGEXREPLACE(SPLIT(QUERY('Form Responses 4'!B:D,
 "select D
  where C >= date '"&TEXT(B5, "yyyy-mm-dd")&"'
    and C <= date '"&TEXT(B6, "yyyy-mm-dd")&"'"& 
    IF(B4<>"all", "and B = '"&B4&"'", )&
    IF(B3<>"all", "and D contains '"&B3&"'", )&" 
  order by C asc", 1), ";"), "^, ", )}))

0