按 ID 分组并按 Google Sheet 或 Excel 中的 SUB UNIQUE ID 计数

Group By ID and COUNT By SUB UNIQUE ID in Google Sheet or Excel

我在 Google 表格中有这些数据(在 Excel 中很可能是相同的原理)

ID     SUB ID    COUNT Unique Sub-ID

1       1A         2
1       1A         2 
1       1B         2
2       2A         1
3       3A         3
3       3B         3
3       3B         3
3       3D         3

所以举例来说,ID 1有1A和1B,两个唯一的子ID。我如何在 Google 张中这样计算?

如果你想使用数组公式,你可以试试这个:

=ArrayFormula({unique(filter(A2:A,A2:A<>"")),countif(index(unique(A2:B),0,1),unique(filter(A2:A,A2:A<>"")))})

使用:

=ARRAYFORMULA(IFNA(VLOOKUP(A1:A, QUERY(UNIQUE(A1:B), 
 "select Col1,count(Col2) where Col1 is not null group by Col1"), 2, 0)))