如何在 Google 表格中使用 ArrayFormula 計算總數和唯一性(基於 2 個單獨的列)? (How to count totals and uniques (based on 2 separate columns) using ArrayFormula in Google Sheets?)


問題描述

如何在 Google 表格中使用 ArrayFormula 計算總數和唯一性(基於 2 個單獨的列)? (How to count totals and uniques (based on 2 separate columns) using ArrayFormula in Google Sheets?)

我有以下電子表格:

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

前 2 列計算操作總數並對其進行排序。我想要做的也是使用相同的公式生成接下來的 2 列。第 3 列用於計算基於用戶 ID 的唯一操作數,第 4 列用於計算基於用戶名的唯一操作數。我可以做一個單獨計算唯一性的公式,但理想情況下,我希望它與前 2 列一起使用。

非常感謝任何幫助。<


參考解法

方法 1:

Try the following formula in cell A10 or any free cell except in columns F,G and 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))})

To get sorted (by column 2) result, try:

=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))})

方法 2:

use:

=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

(by darkhorseKishanplayer0)

參考文件

  1. How to count totals and uniques (based on 2 separate columns) using ArrayFormula in Google Sheets? (CC BY‑SA 2.5/3.0/4.0)

#google-sheets-query #google-sheets #google-sheets-formula #array-formulas #gs-vlookup






相關問題

IMPORTRANGE 將多個 Google 表格導入一個垂直列? (IMPORTRANGE to import multiple Google Sheets into one vertical column?)

如何使用度量單位對類似項目進行分組和添加 (How to group and add similar items with a unit of measurement)

如何在 Google 表格中創建多個工作表引用的 INDIRECT 數組字符串? (How to create INDIRECT array string of multiple sheet references in Google Sheets?)

如何匯總 Google 表格中列中的前 5 個值 (How can I sum top 5 values from column in Google Sheets)

使用查詢和過濾但“無列:Col15”錯誤 (Use Query and filter But "No Column: Col15" error)

如何從 Google 表格中的字符串中刪除一組數字 (how to remove a set of digits from string in Google Sheets)

如何在 Google 表格中使用 ArrayFormula 計算總數和唯一性(基於 2 個單獨的列)? (How to count totals and uniques (based on 2 separate columns) using ArrayFormula in Google Sheets?)

從其他行的組合創建行 (Create rows from combination of other rows)

將一對多數據轉換為列 (Transform one to many data to columns)

希望從右到左計算零值,直到出現非零值 (Looking to count zero values from right to left until non-zero values appears)

使用 ImportHTML 或 ImportXML 在 Google 表格中選擇不連續的列、刪除行和添加排序列 (Using ImportHTML or ImportXML to Select Non-Consecutive Columns In Google Sheets, Remove Rows, & Add A Sort Column)

使用 ARRAYFORMULA 從查找表中查找源表中的所有匹配行/值 (use ARRAYFORMULA to find all matching rows/values in a source table from a lookup table)







留言討論