如何使用Google表格中的ArrayFormula计算总数和唯一性(基于2个单独的列)?

时间:2020-01-30 06:04:00

标签: google-sheets google-sheets-formula array-formulas google-sheets-query gs-vlookup

我有以下电子表格:

https://docs.google.com/spreadsheets/d/1pBL21fyuxYNb5YfERsFl7Y-CTdQEH7SgJQfuOdQ0V6c/edit?usp=sharing

前2列计算操作总数并对其进行排序。我还想使用相同的公式生成接下来的2列。第3列用于根据用户ID计算唯一的操作数,第4列用于根据用户名计算唯一的操作数。我可以创建一个单独计算唯一性的公式,但是理想情况下,我希望它可以与前两列一起使用。

非常感谢您的帮助。

2 个答案:

答案 0 :(得分:2)

在单元格A10或除F,G和H列之外的任何空闲单元格中尝试以下公式:

=arrayformula({query({F3:F,F3:F},"select Col1,count(Col2) where Col1<>'' group by Col1 label count(Col2) 'Total'",1),iferror(vlookup(query(query({F3:F,F3:F},"select Col1,count(Col2) where Col1<>'' group by Col1 label count(Col2) 'Total'",1),"select Col1"),query(query({F3:G,G3:G},"select Col1,Col2,count(Col3) where Col1<>'' group by Col1,Col2 label count(Col3) 'Total'",1),"select Col1,count(Col2) group by Col1 label count(Col2) 'Unique (for id)'",1),2,0)),iferror(vlookup(query(query({F3:F,F3:F},"select Col1,count(Col2) where Col1<>'' group by Col1 label count(Col2) 'Total'",1),"select Col1"),query(query({F3:F,H3:H,H3:H},"select Col1,Col2,count(Col3) where Col1<>'' group by Col1,Col2 label count(Col3) 'Total'",1),"select Col1,count(Col2) group by Col1 label count(Col2) 'Unique (for name)'",1),2,0))})

要对结果(按第2列进行排序)进行尝试,

=arrayformula({query({F3:F,F3:F},"select Col1,count(Col2) where Col1<>'' group by Col1 order by count(Col2) desc label count(Col2) 'Total'",1),iferror(vlookup(query(query({F3:F,F3:F},"select Col1,count(Col2) where Col1<>'' group by Col1 order by count(Col2) desc label count(Col2) 'Total'",1),"select Col1"),query(query({F3:G,G3:G},"select Col1,Col2,count(Col3) where Col1<>'' group by Col1,Col2 label count(Col3) 'Total'",1),"select Col1,count(Col2) group by Col1 label count(Col2) 'Unique (for id)'",1),2,0)),iferror(vlookup(query(query({F3:F,F3:F},"select Col1,count(Col2) where Col1<>'' group by Col1 order by count(Col2) desc label count(Col2) 'Total'",1),"select Col1"),query(query({F3:F,H3:H,H3:H},"select Col1,Col2,count(Col3) where Col1<>'' group by Col1,Col2 label count(Col3) 'Total'",1),"select Col1,count(Col2) group by Col1 label count(Col2) 'Unique (for name)'",1),2,0))})

答案 1 :(得分:1)

使用:

=ARRAYFORMULA(QUERY({F3:H, 
 IF((G3:G<>"")*(COUNTIFS(F3:F&G3:G, F3:F&G3:G, ROW(G3:G), "<="&ROW(G3:G))=1), F3:F&G3:G, ),
 IF((H3:H<>"")*(COUNTIFS(F3:F&H3:H, F3:F&H3:H, ROW(H3:H), "<="&ROW(H3:H))=1), F3:F&H3:H, )},
 "select Col1,count(Col1),count(Col4),count(Col5) 
  where Col1 !='' 
  group by Col1 
  order by count(Col1) desc 
  label count(Col1)'Total',
        count(Col4)'Unique (for id)',
        count(Col5)'Unique (for name)'", 1))

enter image description here