将层级代码拆分为父项目(Google 工作表
Splitting hierarchical codes into parent items (Google Sheets
源单元格:CCA, BF
结果单元格:C, CC, CCA, B, BF
CCA
是与层次结构相关的复杂代码。这意味着,CCA
是 CC
的子项,CC
是 C
的子项。因此,该公式应拆分为所有父项(C
和 CC
)并保留子项(CC
A)——并对字符串的串联列表执行此操作。当前最大级别为四 (ABCD
),但将来可能会更多。
我不知道如何为此创建公式,但我得到了这个公式:=arrayformula( join( ", ", unique( flatten( transpose( left( split(A2, ", ", true, true), sequence( max( len( split(A2, ", ", true, true) ) ) ) ) ) ) ) ) )
参见 post here。
但是我需要一个数组公式,因为它可以应用于整个列
一部分的研究数据相关联
尝试:
=ARRAYFORMULA(REGEXREPLACE(FLATTEN(TRIM(QUERY(QUERY(QUERY({IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A1:A3, ", ")),,TEXT(ROW(A1:A3), "♥00000"))), "×")),
SEQUENCE(COLUMNS(SPLIT(A1:A3, ", "))*MAX(LEN(TRIM(SPLIT(QUERY(A1:A3&",",,9^9), ", "))))),
TRIM(FLATTEN(QUERY(IFERROR(REGEXREPLACE(SORT(TRANSPOSE(REGEXREPLACE(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A1:A3, ", ")),,REPT(SPLIT(A1:A3, ", ")&"×", LEN(SPLIT(A1:A3, ", "))))), "×"),
{"(×)", "("&REPT(".", SEQUENCE(1, MAX(LEN(TRIM(SPLIT(QUERY(A1:A3&",",,9^9), ", "))))-1))&")$"}, )&","),
SEQUENCE(MAX(LEN(TRIM(SPLIT(QUERY(A1:A3&",",,9^9), ", "))))), 0), "^,$", )),,9^9)))},
"select max(Col3) where Col1 is not null group by Col2 pivot Col1"), "offset 1", 0),,9^9))), ",$", ))
non-english 张:
=ARRAYFORMULA(REGEXREPLACE(FLATTEN(TRIM(QUERY(QUERY(QUERY({IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A1:A3; ", "));;TEXT(ROW(A1:A3); "♥00000"))); "×"))\
SEQUENCE(COLUMNS(SPLIT(A1:A3; ", "))*MAX(LEN(TRIM(SPLIT(QUERY(A1:A3&",";;9^9); ", ")))))\
TRIM(FLATTEN(QUERY(IFERROR(REGEXREPLACE(SORT(TRANSPOSE(REGEXREPLACE(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A1:A3; ", "));;REPT(SPLIT(A1:A3; ", ")&"×"; LEN(SPLIT(A1:A3; ", "))))); "×");
{"(×)"\ "("&REPT("."; SEQUENCE(1; MAX(LEN(TRIM(SPLIT(QUERY(A1:A3&",";;9^9); ", "))))-1))&")$"}; )&",");
SEQUENCE(MAX(LEN(TRIM(SPLIT(QUERY(A1:A3&",";;9^9); ", "))))); 0); "^,$"; ));;9^9)))};
"select max(Col3) where Col1 is not null group by Col2 pivot Col1"); "offset 1"; 0);;9^9))); ",$"; ))
更新:
=ARRAYFORMULA(REGEXREPLACE(FLATTEN(TRIM(QUERY(QUERY(QUERY({IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A2:A; ", "));;TEXT(ROW(A2:A); "♥00000"))); "×"))\
SEQUENCE(ROWS(IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A2:A; ", "));;TEXT(ROW(A2:A); "♥00000"))); "×"))))\
TRIM(FLATTEN(QUERY(IFERROR(REGEXREPLACE(SORT(TRANSPOSE(REGEXREPLACE(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A2:A; ", "));;REPT(SPLIT(A2:A; ", ")&"×"; LEN(SPLIT(A2:A; ", "))))); "×");
{"(×)"\ "("&REPT("."; SEQUENCE(1; MAX(LEN(TRIM(SPLIT(QUERY(A2:A&",";;9^9); ", "))))-1))&")$"}; )&",");
SEQUENCE(MAX(LEN(TRIM(SPLIT(QUERY(A2:A&",";;9^9); ", "))))); 0); "^,$"; ));;9^9)))};
"select max(Col3) where Col1 is not null group by Col2 pivot Col1"); "offset 1"; 0);;9^9))); ",$"; ))
但是如果你有大数据集,最好(更快)将它分成如下块:
=ARRAYFORMULA({REGEXREPLACE(FLATTEN(TRIM(QUERY(QUERY(QUERY({IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A2:A600; ", "));;TEXT(ROW(A2:A600); "♥00000"))); "×"))\
SEQUENCE(ROWS(IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A2:A600; ", "));;TEXT(ROW(A2:A600); "♥00000"))); "×"))))\
TRIM(FLATTEN(QUERY(IFERROR(REGEXREPLACE(SORT(TRANSPOSE(REGEXREPLACE(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A2:A600; ", "));;REPT(SPLIT(A2:A600; ", ")&"×"; LEN(SPLIT(A2:A600; ", "))))); "×");
{"(×)"\ "("&REPT("."; SEQUENCE(1; MAX(LEN(TRIM(SPLIT(QUERY(A2:A600&",";;9^9); ", "))))-1))&")$"}; )&",");
SEQUENCE(MAX(LEN(TRIM(SPLIT(QUERY(A2:A600&",";;9^9); ", "))))); 0); "^,$"; ));;9^9)))};
"select max(Col3) where Col1 is not null group by Col2 pivot Col1"); "offset 1"; 0);;9^9))); ",$"; );
REGEXREPLACE(FLATTEN(TRIM(QUERY(QUERY(QUERY({IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A601:A; ", "));;TEXT(ROW(A601:A); "♥00000"))); "×"))\
SEQUENCE(ROWS(IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A601:A; ", "));;TEXT(ROW(A601:A); "♥00000"))); "×"))))\
TRIM(FLATTEN(QUERY(IFERROR(REGEXREPLACE(SORT(TRANSPOSE(REGEXREPLACE(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A601:A; ", "));;REPT(SPLIT(A601:A; ", ")&"×"; LEN(SPLIT(A601:A; ", "))))); "×");
{"(×)"\ "("&REPT("."; SEQUENCE(1; MAX(LEN(TRIM(SPLIT(QUERY(A601:A&",";;9^9); ", "))))-1))&")$"}; )&",");
SEQUENCE(MAX(LEN(TRIM(SPLIT(QUERY(A601:A&",";;9^9); ", "))))); 0); "^,$"; ));;9^9)))};
"select max(Col3) where Col1 is not null group by Col2 pivot Col1"); "offset 1"; 0);;9^9))); ",$"; )})
源单元格:CCA, BF
结果单元格:C, CC, CCA, B, BF
CCA
是与层次结构相关的复杂代码。这意味着,CCA
是 CC
的子项,CC
是 C
的子项。因此,该公式应拆分为所有父项(C
和 CC
)并保留子项(CC
A)——并对字符串的串联列表执行此操作。当前最大级别为四 (ABCD
),但将来可能会更多。
我不知道如何为此创建公式,但我得到了这个公式:=arrayformula( join( ", ", unique( flatten( transpose( left( split(A2, ", ", true, true), sequence( max( len( split(A2, ", ", true, true) ) ) ) ) ) ) ) ) )
参见 post here。
但是我需要一个数组公式,因为它可以应用于整个列
一部分的研究数据相关联尝试:
=ARRAYFORMULA(REGEXREPLACE(FLATTEN(TRIM(QUERY(QUERY(QUERY({IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A1:A3, ", ")),,TEXT(ROW(A1:A3), "♥00000"))), "×")),
SEQUENCE(COLUMNS(SPLIT(A1:A3, ", "))*MAX(LEN(TRIM(SPLIT(QUERY(A1:A3&",",,9^9), ", "))))),
TRIM(FLATTEN(QUERY(IFERROR(REGEXREPLACE(SORT(TRANSPOSE(REGEXREPLACE(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A1:A3, ", ")),,REPT(SPLIT(A1:A3, ", ")&"×", LEN(SPLIT(A1:A3, ", "))))), "×"),
{"(×)", "("&REPT(".", SEQUENCE(1, MAX(LEN(TRIM(SPLIT(QUERY(A1:A3&",",,9^9), ", "))))-1))&")$"}, )&","),
SEQUENCE(MAX(LEN(TRIM(SPLIT(QUERY(A1:A3&",",,9^9), ", "))))), 0), "^,$", )),,9^9)))},
"select max(Col3) where Col1 is not null group by Col2 pivot Col1"), "offset 1", 0),,9^9))), ",$", ))
non-english 张:
=ARRAYFORMULA(REGEXREPLACE(FLATTEN(TRIM(QUERY(QUERY(QUERY({IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A1:A3; ", "));;TEXT(ROW(A1:A3); "♥00000"))); "×"))\
SEQUENCE(COLUMNS(SPLIT(A1:A3; ", "))*MAX(LEN(TRIM(SPLIT(QUERY(A1:A3&",";;9^9); ", ")))))\
TRIM(FLATTEN(QUERY(IFERROR(REGEXREPLACE(SORT(TRANSPOSE(REGEXREPLACE(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A1:A3; ", "));;REPT(SPLIT(A1:A3; ", ")&"×"; LEN(SPLIT(A1:A3; ", "))))); "×");
{"(×)"\ "("&REPT("."; SEQUENCE(1; MAX(LEN(TRIM(SPLIT(QUERY(A1:A3&",";;9^9); ", "))))-1))&")$"}; )&",");
SEQUENCE(MAX(LEN(TRIM(SPLIT(QUERY(A1:A3&",";;9^9); ", "))))); 0); "^,$"; ));;9^9)))};
"select max(Col3) where Col1 is not null group by Col2 pivot Col1"); "offset 1"; 0);;9^9))); ",$"; ))
更新:
=ARRAYFORMULA(REGEXREPLACE(FLATTEN(TRIM(QUERY(QUERY(QUERY({IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A2:A; ", "));;TEXT(ROW(A2:A); "♥00000"))); "×"))\
SEQUENCE(ROWS(IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A2:A; ", "));;TEXT(ROW(A2:A); "♥00000"))); "×"))))\
TRIM(FLATTEN(QUERY(IFERROR(REGEXREPLACE(SORT(TRANSPOSE(REGEXREPLACE(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A2:A; ", "));;REPT(SPLIT(A2:A; ", ")&"×"; LEN(SPLIT(A2:A; ", "))))); "×");
{"(×)"\ "("&REPT("."; SEQUENCE(1; MAX(LEN(TRIM(SPLIT(QUERY(A2:A&",";;9^9); ", "))))-1))&")$"}; )&",");
SEQUENCE(MAX(LEN(TRIM(SPLIT(QUERY(A2:A&",";;9^9); ", "))))); 0); "^,$"; ));;9^9)))};
"select max(Col3) where Col1 is not null group by Col2 pivot Col1"); "offset 1"; 0);;9^9))); ",$"; ))
但是如果你有大数据集,最好(更快)将它分成如下块:
=ARRAYFORMULA({REGEXREPLACE(FLATTEN(TRIM(QUERY(QUERY(QUERY({IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A2:A600; ", "));;TEXT(ROW(A2:A600); "♥00000"))); "×"))\
SEQUENCE(ROWS(IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A2:A600; ", "));;TEXT(ROW(A2:A600); "♥00000"))); "×"))))\
TRIM(FLATTEN(QUERY(IFERROR(REGEXREPLACE(SORT(TRANSPOSE(REGEXREPLACE(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A2:A600; ", "));;REPT(SPLIT(A2:A600; ", ")&"×"; LEN(SPLIT(A2:A600; ", "))))); "×");
{"(×)"\ "("&REPT("."; SEQUENCE(1; MAX(LEN(TRIM(SPLIT(QUERY(A2:A600&",";;9^9); ", "))))-1))&")$"}; )&",");
SEQUENCE(MAX(LEN(TRIM(SPLIT(QUERY(A2:A600&",";;9^9); ", "))))); 0); "^,$"; ));;9^9)))};
"select max(Col3) where Col1 is not null group by Col2 pivot Col1"); "offset 1"; 0);;9^9))); ",$"; );
REGEXREPLACE(FLATTEN(TRIM(QUERY(QUERY(QUERY({IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A601:A; ", "));;TEXT(ROW(A601:A); "♥00000"))); "×"))\
SEQUENCE(ROWS(IFERROR(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A601:A; ", "));;TEXT(ROW(A601:A); "♥00000"))); "×"))))\
TRIM(FLATTEN(QUERY(IFERROR(REGEXREPLACE(SORT(TRANSPOSE(REGEXREPLACE(SPLIT(FLATTEN(
IF(""=IFERROR(SPLIT(A601:A; ", "));;REPT(SPLIT(A601:A; ", ")&"×"; LEN(SPLIT(A601:A; ", "))))); "×");
{"(×)"\ "("&REPT("."; SEQUENCE(1; MAX(LEN(TRIM(SPLIT(QUERY(A601:A&",";;9^9); ", "))))-1))&")$"}; )&",");
SEQUENCE(MAX(LEN(TRIM(SPLIT(QUERY(A601:A&",";;9^9); ", "))))); 0); "^,$"; ));;9^9)))};
"select max(Col3) where Col1 is not null group by Col2 pivot Col1"); "offset 1"; 0);;9^9))); ",$"; )})