简体   繁体   English

结合 Google 表格查询、IMPORTRANGE 和 AVERAGE 函数

[英]Combine Google Sheets Query, IMPORTRANGE, and AVERAGE functions

I'm trying to aggregate an average value using Query and IMPORTRANGE so I can compare the index numbers of the two tables.我正在尝试使用 Query 和 IMPORTRANGE 聚合平均值,以便可以比较两个表的索引号。

=QUERY(IMPORTRANGE("Table ","Sheet:B,C"),"Select avg(Col2) where Col1='"&A2&"'",0)

File 1:文件 1:

Table 1 Index表 1 索引 Above formula以上公式
1 1 =QUERY(IMPORTRANGE("URL","Sheet:I,J"),"Select avg(Col2) where Col1='"&A2&"'",0) =QUERY(IMPORTRANGE("URL","Sheet:I,J"),"Select avg(Col2) where Col1='"&A2&"'",0)

File 2:文件 2:

Table 2 Index表 2 索引 Table 1 Index Match表 1 索引匹配 Data数据
1 1 1 1 2.0 2.0
2 2 1 1 10.0 10.0

But it returns empty.但它返回空。 When I remove avg() , then I get an error that the dataset is empty.当我删除avg()时,我收到一个错误,即数据集为空。 So somewhere I made a mistake, and it's not comparing File 2 Column B against File 1 Column A properly.所以在某个地方我犯了一个错误,它没有正确比较文件 2 列 B 和文件 1 列 A。 I have the IMPORTRANGE() selecting columns B and C, so that means I'm trying to average Col2 and comparing Col1 to A2 , but I can't see the error there.我有IMPORTRANGE()选择列 B 和 C,这意味着我正在尝试平均Col2并将Col1A2进行比较,但我看不到那里的错误。

try:尝试:

=QUERY(IMPORTRANGE("ID", "Sheet!B:C"), 
 "select Col1,avg(Col2) 
  where Col1 is not null 
  group by Col1
  label avg(Col2)''", 0)

I did a workaround and incorporated a hidden "Meta Data" tab.我做了一个解决方法并合并了一个隐藏的“元数据”选项卡。

I used IMPORTRANGE() to get all of the Table 1 indices that could exist into Sheet 2 Meta Data tab, did an AVERAGEIF() down column 2 that would aggregate Table 2's data into an average if it matches the imported range in column 1. Then just used a VLOOKUP(IMPORTRANGE()) combo in Sheet 1 Table 1 to bring the aggregation back.我使用IMPORTRANGE()来获取可能存在于 Sheet 2 Meta Data 选项卡中的所有表 1 索引,在第 2 列下执行AVERAGEIF() ,如果它与第 1 列中的导入范围匹配,则将表 2 的数据聚合为平均值。然后只需使用表 1 表 1 中的VLOOKUP(IMPORTRANGE())组合来恢复聚合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM