Create Percentage Table from 2 other tables - Google Query

流过昼夜 提交于 2021-01-01 07:52:00

问题


Is there a way to calculate a 3rd crosstab Table containing percentages from 2 crosstab tables created from Google Queries? Initially i was stacking the 2 queries together using braces, but found that if there were row or column mismatches, then both the table queries would result in #VALUE error. So separated the 2 tables with 100 grouped rows between them. I want to calculate FTR percentage table below these tables.

Here is an FTRTable with Edit access.

You can refer to my earlier related post here.


回答1:


formula for FTR table:

=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+♥)", ))


and all 3 tables in one formula fully dynamic:

=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



来源:https://stackoverflow.com/questions/65212862/create-percentage-table-from-2-other-tables-google-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!