在具有多个数据源的查询中添加源列

huangapple go评论61阅读模式
英文:

Add source column in QUERY with more than one data sources

问题

=QUERY({'yr Import'!A2:BH; 'ar Import'!A2:BH, ARRAYFORMULA("yr Import"); ARRAYFORMULA("ar Import")},"Select * where Col1 is not null")

英文:

I use the following formula to combine the data of two google sheet tabs in one sheet:

=QUERY({'yr Import'!A2:BH;'ar Import'!A2:BH},"Select * where Col1 is not null ")

I want to change the formula, that I get an additional column (after the imported data) with the source name of the data.

Data of A2:BH Addtional Source column
... yr Import
... ar Import
... yr Import
... yr Import
... yr Import
... ar Import
... ar Import
... ar Import
... ar Import

I tried for exampe to add an arrayformula:

=QUERY({'yr Import'!A2:BM, ARRAYFORMULA("yr Import") ;'ar Import'!A2:BM, ARRAYFORMULA("ar Import")},"Select * where Col1 is not null")

--> This leads to an "#REF!" error!

答案1

得分: 2

<!-- language-all: js -->

*这是一种您可以尝试的方法:*

    =let(yr, "年 Import", ar, "ar Import",
         query({{'年 Import'!A2:BH,wrapcols(yr,rows('年 Import'!A2:A),yr)};
                {'ar Import'!A2:BH,wrapcols(ar,rows('ar Import'!A2:A),ar)},"where Col1 is not null"))
英文:

<!-- language-all: js -->

Here's one approach you may test out:

=let(yr,&quot;yr Import&quot;, ar,&quot;ar Import&quot;,
     query({{&#39;yr Import&#39;!A2:BH,wrapcols(yr,rows(&#39;yr Import&#39;!A2:A),yr)};
            {&#39;ar Import&#39;!A2:BH,wrapcols(ar,rows(&#39;ar Import&#39;!A2:A),ar)}},&quot;where Col1 is not null&quot;))

huangapple
  • 本文由 发表于 2023年6月26日 17:07:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76555195.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定