计算某些文本组合在某些列中出现的次数

时间:2019-10-15 07:42:08

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

我有一个包含多列和大约1000行的数据集。我需要找出可以在数据集中找到某些列组合的次数。

在下面的示例中,列A:B代表原始数据集。在C2中,我有一个公式,可以从列A:B中查找所有非唯一组合。我需要一个公式,该公式计算在C:D列中找到A:B列中的组合的次数。所需的输出应该在ColE中。

Pleas see this example!

2 个答案:

答案 0 :(得分:0)

共享电子表格的副本总是更好,但是尝试输入E1

={"Count"; ArrayFormula(IF(LEN(C2:C), VLOOKUP(C2:C&D2:D, query({A2:A&B2:B, A2:B}, "Select Col1, count(Col3) where Col1 <>'' group by Col1"), 2, 0),))}

看看是否可行?

enter image description here

请注意,您可以使用单个公式创建相同的输出(C,D和E列)

=query(ArrayFormula(query({A2:B, A2:A&B2:B}, "Select Col1, Col2, count(Col3) where Col1 <>'' group by Col1, Col2")), "where Col3 >1 label Col1 'Value 1', Col2 'Value 2'")

enter image description here

答案 1 :(得分:0)

您可以一次完成所有操作...删除C,D,E列并使用以下公式:

=ARRAYFORMULA(QUERY({A2:B, A2:A&B2:B}, 
 "select Col1,Col2,count(Col3) 
  where Col1 is not null 
  group by Col1,Col2 
  order by count(Col3) desc 
  label count(Col3)''"))

0


对于选定的组合,仅在 E2 单元格中使用此公式:

=ARRAYFORMULA(IFERROR(VLOOKUP(C2:C&D2:D, QUERY({A2:A&B2:B}, 
 "select Col1,count(Col1) 
  where Col1 is not null 
  group by Col1  
  label count(Col1)''"), 2, 0)))

0

相关问题