如何通过特定ID聚合字符串-(String1-a)(String1-b)(String2-a)(String2-b)

时间:2019-09-03 17:56:29

标签: regex google-sheets array-formulas google-sheets-query google-query-language

我需要能够基于字符串值及其标识符值聚合字符串和另一个单元格的值。

我尝试了几种将值求和,按特定项目过滤的方法,然后尝试根据包含的文本求和,但没有找到好的方法。

Then(/^the user clicks on "(.*)" download on "(.*)" page$/) do |field_name, page_name|
  # get the XPATH or CSS from page object file, Raises Error if not found
  begin
    selector, element_path = get_element_target(field_name, page_name).split('^^')
  rescue
    fail("Element Xpath is not found for #{field_name} in #{page_name} page objects File")
  end
  if selector.nil? || element_path.nil?
    fail("Element Xpath is not found for #{field_name} in #{page_name} page objects File")
  end
  selector = (selector.downcase.include? 'xpath') ? :xpath : :css

  # Create the Element object
  element_obj = @browser.element(selector, element_path)

  # Wait for element to be present
  wait_for_element(element_obj)

  # Focus on element to make it visible
  focus_on_element(element_obj)
  DOWNLOAD_DIR = "#{Dir.pwd}" + '/features/support/Downloads/'


  element_obj.click(DOWNLOAD_DIR)

  end

我不确定如何对sum(A)和sum(B)进行处理,其中A包含相同的文本,但不包括标识符。

当前,我正在执行查询以仅从较大的数据集中获取A和B,然后执行$ ldd /usr/bin/gdb | grep python libpython3.7m.so.1.0 => /lib64/libpython3.7m.so.1.0 (0x00007f39f9c37000) 来删除所有╔══════════════╦═════════════════╗ ║ A ║ B ║ ╠══════════════╬═════════════════╣ ║ Product Name ║ Product Quantity║ ╠══════════════╬═════════════════╣ ║ ProductA - 1 ║ 12 ║ ╠══════════════╬═════════════════╣ ║ ProductA - 2 ║ 2 ║ ╠══════════════╬═════════════════╣ ║ ProductB - 1 ║ 28 ║ ╠══════════════╬═════════════════╣ ║ ProductB - 2 ║ 21 ║ ╠══════════════╬═════════════════╣ ║ ProductC - 1 ║ 1 ║ ╠══════════════╬═════════════════╣ ║ ProductC - 2 ║ 4 ║ ╠══════════════╬═════════════════╣ ║ ProductD - 1 ║ 98 ║ ╠══════════════╬═════════════════╣ ║ ProductD - 2 ║ 75 ║ ╠══════════════╬═════════════════╣ ║ ProductE - 1 ║ 5 ║ ╠══════════════╬═════════════════╣ ║ ProductE - 2 ║ 9 ║ ╚══════════════╩═════════════════╝ Find and Replace,然后进行

- 1

1 个答案:

答案 0 :(得分:1)

=ARRAYFORMULA(QUERY({IFERROR(REGEXEXTRACT(A2:A, "(.+) - \d+")), B2:B}, 
 "select Col1,sum(Col2) 
  where Col1 is not null 
  group by Col1 
  order by sum(Col2) desc
  label sum(Col2)''", 0))

0