我想像這樣轉換一個范圍/陣列
| Fruit | Strawberry |
| Fruit | Blueberry |
| Fruit | Banana |
| Vegetable | Lettuce |
| Vegetable | Cucumber |
| Vegetable | Carrot |
| Vegetable | Celery |
| Dairy | Milk |
| Dairy | Butter |
| Dairy | Cheese |
成一維陣列,用空格分隔這樣的類別
| Fruit |
| Banana |
| Blueberry |
| Strawberry |
| |
| Vegetable |
| Carrot |
| Celery |
| Cucumber |
| Lettuce |
| |
| Dairy |
| Butter |
| Cheese |
| Milk |
在谷歌表格中。我可以很容易地實作一個沒有空格的一維陣列,原始資料范圍=UNIQUE(FLATTEN(A2:B11))
在哪里;A2:B11但是,我無法獲得分隔類別的所需空間。
有人可以幫忙嗎?
這是示例表:
更新:
=INDEX(SUBSTITUTE(QUERY(FLATTEN(IFERROR(SPLIT(FLATTEN(TRANSPOSE(
QUERY({"?×"&A2:A, B2:B, ROW(A2:A)},
"select max(Col2) group by Col3 pivot Col1"))), "×"))),
"where Col1 is not null offset 2", ), "?", ))

uj5u.com熱心網友回復:
這是說明一種可能方法的草案:
=ArrayFormula(query(regexreplace(unique({"";flatten({A2:B999,if(A2:A999<>A3:A1000,row(A2:A999)&"","")})}),"\d*",""),"offset 1"))

顯然需要對沒有 1000 行的作業表進行概括:
=ArrayFormula(query(regexreplace(unique({"";flatten({A2:B,if(A2:A<>{A3:A;""},row(A2:A)&"","")})}),"\d*",""),"offset 1"))
uj5u.com熱心網友回復:
其他答案很棒。這也可以
=ARRAYFORMULA(
FLATTEN(
QUERY(
QUERY(
{A2:A,B2:B,COUNTIFS(A2:A,A2:A,ROW(A2:A),"<="&ROW(A2:A))},
"select Col1, Max(Col2)
where Col2 is not null
group by Col1
pivot Col3"),
"offset 1",0)))
它使用類別的迭代計數創建資料透視表,然后使用第二個查詢來丟棄這些數字,然后變平。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/481263.html
上一篇:蟒蛇|IF AND陳述句
