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


問題描述

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

我有以下電子表格。我需要壓縮這個電子表格的內容。我想知道是否可以將類似的項目(如 1952)分組並在下一列中添加數字並輸出 5m / 2w 或類似的東西?1951 年將被壓縮到 9w。這些數據不斷變化,並且經常添加新的參考編號。

sheets file

p>

參考解法

方法 1:

Sheets doesn't do well adding numbers when they're right next to letters, so you'll need to split those cells into a number column and letter column using left() and right(). Put the number from left() inside the value() function as well so Sheets knows it's a number.

Example sheet

Once you have the helper columns made, you can use query() to consolidate and sum up your values. Query language can get tricky so I recommend the reference page. Once you have the sums and letters spit out, you can concatenate them in another column (J for me).

方法 2:

=ARRAYFORMULA(SUBSTITUTE(TRIM(SPLIT(TRANSPOSE(QUERY(TRANSPOSE({
 SORT(UNIQUE(INDIRECT("B2:B"&COUNTA(B2:B)+1)&"♦")),IF(ISNUMBER(
 QUERY(QUERY(TO_TEXT(SPLIT(TRANSPOSE(QUERY(TRANSPOSE(QUERY(IFERROR({
 B2:B&"♦", REGEXEXTRACT(C2:C, "\d+")*1, REGEXEXTRACT(C2:C, "\d+(.+)")}), 
 "select Col1,sum(Col2),Col3 
  where Col3 is not null 
  group by Col1,Col3 
  label sum(Col2)''", 0)),,999^99)), "♦")), 
 "select count(Col1) 
  group by Col1 
  pivot Col2", 0), "offset 1", 0)), SUBSTITUTE(
 QUERY(QUERY(TO_TEXT(SPLIT(TRANSPOSE(QUERY(TRANSPOSE(QUERY(IFERROR({
 B2:B&"♦", REGEXEXTRACT(C2:C, "\d+")*1, REGEXEXTRACT(C2:C, "\d+(.+)")}), 
 "select Col1,sum(Col2),Col3 
  where Col3 is not null 
  group by Col1,Col3 
  label sum(Col2)''", 0)),,999^99)), "♦")), 
 "select count(Col1) 
  group by Col1 
  pivot Col2", 0), "limit 0", 1), " ", ), )}),,999^99)), "♦")), " ", " / "))

0

spreadsheet demo

(by AHCBLuke Allpressplayer0)

參考文件

  1. How to group and add similar items with a unit of measurement (CC BY‑SA 2.5/3.0/4.0)

#google-sheets-query #google-sheets #RegEx #google-sheets-formula #array-formulas






相關問題

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)







留言討論