【问题标题】:Create Percentage Table from 2 other tables - Google Query从其他 2 个表创建百分比表 - Google Query
【发布时间】:2020-12-09 08:09:06
【问题描述】:

有没有办法计算第三个交叉表,其中包含从 Google 查询创建的 2 个交叉表的百分比?最初我使用大括号将 2 个查询堆叠在一起,但发现如果存在行或列不匹配,则两个表查询都会导致 #VALUE 错误。因此,将 2 个表分开,它们之间有 100 个分组行。我想在这些表下方计算 FTR 百分比表。

这是一个具有编辑权限的FTRTable

你可以参考我之前的相关帖子here

【问题讨论】:

    标签: google-sheets google-query-language


    【解决方案1】:

    FTR 表公式:

    =ARRAYFORMULA(REGEXREPLACE(TO_TEXT(QUERY(QUERY({QUERY(
     {InputData!D3:D&"♦"&InputData!C3:C, InputData!B3:F, InputData!D3:D&
     IF(InputData!D3:D="",,"♥"&TEXT(InputData!D3:D, "dd/mm/yyyy"))}, 
     "select Col1,Col4,Col3,Col7,count(Col2) 
      where Col4 is not null 
        and year(Col4)="&C1&" 
        and Col5 != 'lost'     
      group by Col1,Col4,Col3,Col7"),
    IFNA(VLOOKUP(INDEX(QUERY({InputData!D3:D&"♦"&InputData!C3:C, InputData!B3:F}, 
     "select Col1,Col4,Col3,count(Col2) 
      where Col4 is not null 
        and year(Col4)="&C1&" 
        and Col5 != 'lost'     
      group by Col1,Col4,Col3"),,1), 
    QUERY({InputData!D3:D&"♦"&InputData!C3:C, InputData!B3:F}, 
     "select Col1,count(Col2) 
      where Col4 is not null 
        and year(Col4)="&C1&" 
        and Col5 != 'lost' 
        and Col6  = 'yes' 
      group by Col1"), 2, 0))}, 
     "select Col4,Col3,Col6/Col5"), 
     "select Col2,max(Col3) 
      group by Col2
      pivot Col1 
      label Col2'FTR%' 
      format max(Col3)'#.00%'")), "(\d+♥)", ))
    


    一个公式中的所有 3 个表格完全动态:

    =ARRAYFORMULA({TRANSPOSE(QUERY(TRANSPOSE(QUERY(IFNA(
     HLOOKUP(INDEX(TRANSPOSE(QUERY(InputData!A3:F, 
     "select D,count(B) 
      where D is not null 
        and year(D)="&C1&" 
        and E!='lost' 
      group by D 
      pivot C 
      label D 'NO OF ISSUES'")), 1), TRANSPOSE(QUERY({InputData!A3:F}, 
     "select Col4,count(Col2) 
      where Col4 is not null
        and year(Col4)="&C1&" 
        and Col5!='lost' 
        and Col6 = 'yes' 
      group by Col4 
      pivot Col3 
      label Col4 'NO OF ISSUES'")), ROW(A1:A10000), 0)), 
     "where Col1 <> '#REF!'")), 
     "format Col1'm/d/yyyy'")); 
     SPLIT(REPT(" ♠", COLUMNS(TRANSPOSE(QUERY(InputData!A3:F, 
     "select D,count(B) 
      where D is not null
        and year(D)="&C1&" 
        and E!='lost' 
      group by D 
      pivot C 
      label D 'TOTAL OPPORTUNITIES'")))), "♠"); 
     TRANSPOSE(QUERY(InputData!A3:F, 
     "select D,count(B) 
      where D is not null
        and year(D)="&C1&" 
        and E!='lost' 
      group by D 
      pivot C 
      label D 'TOTAL OPPORTUNITIES'")); 
     SPLIT(REPT(" ♠", COLUMNS(TRANSPOSE(QUERY(InputData!A3:F, 
     "select D,count(B) 
      where D is not null
        and year(D)="&C1&" 
        and E!='lost' 
      group by D 
      pivot C 
      label D 'TOTAL OPPORTUNITIES'")))), "♠");
     REGEXREPLACE(TO_TEXT(QUERY(QUERY({QUERY(
     {InputData!D3:D&"♦"&InputData!C3:C, InputData!B3:F, InputData!D3:D&
     IF(InputData!D3:D="",,"♥"&TEXT(InputData!D3:D, "m/d/yyyy"))}, 
     "select Col1,Col4,Col3,Col7,count(Col2) 
      where Col4 is not null 
        and year(Col4)="&C1&" 
        and Col5 != 'lost'     
      group by Col1,Col4,Col3,Col7"),
    IFNA(VLOOKUP(INDEX(QUERY({InputData!D3:D&"♦"&InputData!C3:C, InputData!B3:F}, 
     "select Col1,Col4,Col3,count(Col2) 
      where Col4 is not null 
        and year(Col4)="&C1&" 
        and Col5 != 'lost'     
      group by Col1,Col4,Col3"),,1), 
    QUERY({InputData!D3:D&"♦"&InputData!C3:C, InputData!B3:F}, 
     "select Col1,count(Col2) 
      where Col4 is not null 
        and year(Col4)="&C1&" 
        and Col5 != 'lost' 
        and Col6  = 'yes' 
      group by Col1"), 2, 0))}, 
     "select Col4,Col3,Col6/Col5"), 
     "select Col2,max(Col3) 
      group by Col2
      pivot Col1 
      label Col2'FTR%' 
      format max(Col3)'#.00%'")), "(\d+♥)", )})
    

    spreadsheet demo

    【讨论】:

    • 这太棒了,太棒了!谢谢。然而,在我的 A 到 T 列和 6652 行的制作表上,它给出了以下错误Result was not automatically expanded, please insert more rows (8492).,尽管已经插入了 50k 行,有时Formula Parse error。我已经尝试更改参考。可能是什么问题呢?会不会是部分函数处理不了大数据?
    • 我已将生产表列添加到名为Study Report 的新工作表中,并将公式粘贴到Clubbed TablesTables 工作表的O 列中(在您的公式旁边)。现在我收到In ARRAY_LITERAL, an Array Literal was missing values for one or more rows. 我想我在公式中的 REGEXREPLACE 部分之后正确映射 Col1、Col2...等感到困惑。
    • 只需要一种方法来添加 TOTAL Rows 列。对于 FTR% 表,每列都是平均值。
    • 是否可以将总计添加到每个表中?如果一年内没有数据,有没有办法显示空白?我正在尝试像这个查询一样添加总计,但不确定在巨大的公式中添加它的位置。例如对于第一张桌子,{TRANSPOSE(QUERY('Study Report'!$A:$T,"SELECT COUNT(B) WHERE YEAR(S) = "&amp; $C$1 &amp;" AND O != 'NO - all fine' AND L != 'Cancelled' GROUP BY S LABEL COUNT(B) 'TOTAL'",0))}
    • NO OF ISSUES 表计算不正确。请参阅ONION METHOD Sheet。
    猜你喜欢
    • 2016-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多