为逗号分隔列表的每个值创建一行的公式 - GSheets
Formula to create a row for every value of a comma-delimited list - GSheets
我正在尝试编写一个公式,它将采用一组列并将它们配对到单独的行中,并使用逗号分隔列表。在 SQL 中,我会使用左连接来执行此操作,但我不确定如何为此利用 GSheets 函数。
我的意思是:
源数据
Col1
Col2
CommaDelim
Col1Val1
Col2Val1
1,2,3
Col1Val2
Col2Val2
1
Col1Val3
Col2Val3
1,2
Col1Val4
Col2Val4
1,2,3,4
期望输出
Col1
Col2
CommaDelim
Col1Val1
Col2Val1
1
Col1Val1
Col2Val1
2
Col1Val1
Col2Val1
3
Col1Val2
Col2Val2
1
Col1Val3
Col2Val3
1
Col1Val3
Col2Val3
2
Col1Val4
Col2Val4
1
Col1Val4
Col2Val4
2
Col1Val4
Col2Val4
3
Col1Val4
Col2Val4
4
尝试:
=INDEX(QUERY(SPLIT(FLATTEN(A1:A&"×"&B1:B&"×"&SPLIT(C1:C, ",")), "×"),
"where Col3 is not null"))
我正在尝试编写一个公式,它将采用一组列并将它们配对到单独的行中,并使用逗号分隔列表。在 SQL 中,我会使用左连接来执行此操作,但我不确定如何为此利用 GSheets 函数。
我的意思是:
源数据
Col1 | Col2 | CommaDelim |
---|---|---|
Col1Val1 | Col2Val1 | 1,2,3 |
Col1Val2 | Col2Val2 | 1 |
Col1Val3 | Col2Val3 | 1,2 |
Col1Val4 | Col2Val4 | 1,2,3,4 |
期望输出
Col1 | Col2 | CommaDelim |
---|---|---|
Col1Val1 | Col2Val1 | 1 |
Col1Val1 | Col2Val1 | 2 |
Col1Val1 | Col2Val1 | 3 |
Col1Val2 | Col2Val2 | 1 |
Col1Val3 | Col2Val3 | 1 |
Col1Val3 | Col2Val3 | 2 |
Col1Val4 | Col2Val4 | 1 |
Col1Val4 | Col2Val4 | 2 |
Col1Val4 | Col2Val4 | 3 |
Col1Val4 | Col2Val4 | 4 |
尝试:
=INDEX(QUERY(SPLIT(FLATTEN(A1:A&"×"&B1:B&"×"&SPLIT(C1:C, ",")), "×"),
"where Col3 is not null"))