Google表格,将2张纸合并为一张的数组公式,并附加一个新列以指定数据来自哪个表

发布于 2025-02-08 22:38:48 字数 1159 浏览 3 评论 0原文

我正在尝试合并Sheet1& Sheet2到Sheet3。在Sheep3上,我希望A列A显示数据来自哪个表。

Sheet1(源#1)

AB
John Doe123 Street

Sheet2(源#2)

AB
Jane Smith999 Street

Sheet3-使用以下公式进行预期结果。

ABC
Sheet1John Doe123 Street
Sheet2Jane Smith999 Street

我尝试了以下配方。

=ARRAYFORMULA(
  {
    {"Sheet1",FILTER('Sheet1'!A1:B,'Sheet1'!A1:A<>"")};
    {"Sheet2",FILTER('Sheet2'!A1:B,'Sheet1'!A1:A<>"")}
  }
)
=ARRAYFORMULA(
  {
    {"Sheet1",QUERY('Sheet1'!A1:B,"SELECT * WHERE A is not null")};
    {"Sheet2",QUERY('Sheet2'!A1:B,"SELECT * WHERE A is not null")}
  }
)

两者都会给出错误:在Array_literal中,一个或多个行的数组是缺少的值。

我在做什么错?谢谢!

I am trying to merge Sheet1 & Sheet2 into Sheet3. On Sheet3 I would like Column A to display which Sheet the data came from.

Sheet1 (Source #1)

AB
John Doe123 Street

Sheet2 (Source #2)

AB
Jane Smith999 Street

Sheet3 - Expected results using the formulas below.

ABC
Sheet1John Doe123 Street
Sheet2Jane Smith999 Street

I have tried the following formulas.

=ARRAYFORMULA(
  {
    {"Sheet1",FILTER('Sheet1'!A1:B,'Sheet1'!A1:A<>"")};
    {"Sheet2",FILTER('Sheet2'!A1:B,'Sheet1'!A1:A<>"")}
  }
)
=ARRAYFORMULA(
  {
    {"Sheet1",QUERY('Sheet1'!A1:B,"SELECT * WHERE A is not null")};
    {"Sheet2",QUERY('Sheet2'!A1:B,"SELECT * WHERE A is not null")}
  }
)

Both give the error: In ARRAY_LITERAL, an Array Literal was missing values for one or more rows.

What am I doing wrong? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小糖芽 2025-02-15 22:38:48

尝试:

={QUERY(Sheet1!A:B; "select 'Sheet1',A,B label 'Sheet1'''"; ); 
  QUERY(Sheet2!A:B; "select 'Sheet2',A,B label 'Sheet2'''"; )}

Try:

={QUERY(Sheet1!A:B; "select 'Sheet1',A,B label 'Sheet1'''"; ); 
  QUERY(Sheet2!A:B; "select 'Sheet2',A,B label 'Sheet2'''"; )}
旧梦荧光笔 2025-02-15 22:38:48

由于您无法将表名称附加到多行,因此您需要获得创意。

这样做的是将列组合成一个,并将每行的表格与查询中使用的相同定界符一起添加。然后附加两个结果,然后使用上述定界符将它们分开。

公式:

=ARRAYFORMULA(SPLIT({
{"Sheet1×"&QUERY({Sheet1!A1:A&"×"&Sheet1!B1:B}, "where Col1 != '×'")};
{"Sheet2×"&QUERY({Sheet2!A1:A&"×"&Sheet2!B1:B}, "where Col1 != '×'")}
}, "×")

输出:

“输出”

Since you can't append the sheet name to multiple rows, you need to get creative.

What this does is combine the columns into one and append the sheet name per row together with the same delimiter used inside the query. Then append both results then proceed to split them using the said delimiter.

Formula:

=ARRAYFORMULA(SPLIT({
{"Sheet1×"&QUERY({Sheet1!A1:A&"×"&Sheet1!B1:B}, "where Col1 != '×'")};
{"Sheet2×"&QUERY({Sheet2!A1:A&"×"&Sheet2!B1:B}, "where Col1 != '×'")}
}, "×")

Output:

output

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文