在 Google 个工作表中过滤通过 QUERY 动态创建的范围
Filter a range created dynamically via QUERY in Google Sheets
我目前正在使用这个查询
=sort({IFERROR(query('PI Calcs'!C4:K51,"select C,G,H, K where C is not null and G > 0"),{"","","",""});IFERROR(query('PI Calcs'!C54:P101,"select C,J,K,P where C is not null and J > 0"),{"","","",""});IFERROR(query('PI Calcs'!C104:P127,"select C,J,K,P where C is not null and J > 0"),{"","","",""})},2,false)
我通过使用 QUERY 将 3 个范围连接在一起。我正在使用 IFERROR,因为如果任何查询 return 是一个空集,那么我无法将它们合并在一起,失败结果是一个包含 4 个值的空行。
我的困难是从最终集中删除那些空值,因为在对它们进行排序时,每个失败的查询都会得到 1 个空行。我试过使用 FILTER,但我无法引用范围内的列,因为它是动态创建的。
如何从动态创建的范围中过滤掉空白行?
有没有一种方法可以在不返回空范围的情况下查询和连接结果?
为什么不查询您的查询?
=QUERY({IFERROR(query('PI Calcs'!C4:K51,"select C,G,H, K where C is not null and G > 0"),{"","","",""});IFERROR(query('PI Calcs'!C54:P101,"select C,J,K,P where C is not null and J > 0"),{"","","",""});IFERROR(query('PI Calcs'!C104:P127,"select C,J,K,P where C is not null and J > 0"),{"","","",""})},"where Col1 is not null order by Col2 desc",0)
试试这个较短的:
=QUERY(SORT({IFERROR(QUERY('PI Calcs'!C4:K51,
"select C,G,H,K
where C is not null
and G > 0"), {"","","",""});
IFERROR(QUERY({'PI Calcs'!C54:P101; 'PI Calcs'!C104:P127},
"select Col1,Col8,Col9,Col14
where Col1 is not null
and Col8 > 0"), {"","","",""}), 2, 0),
"where Col1 is not null", 0)
甚至更短:
=QUERY({'PI Calcs'!C54:P101; 'PI Calcs'!C104:P127;
{'PI Calcs'!C4:I51, 'PI Calcs'!G4:L51,'PI Calcs'!K4:K51}},
"select Col1,Col8,Col9,Col14
where Col1 is not null
and Col8 > 0
order by Col2 desc", 0)
我目前正在使用这个查询
=sort({IFERROR(query('PI Calcs'!C4:K51,"select C,G,H, K where C is not null and G > 0"),{"","","",""});IFERROR(query('PI Calcs'!C54:P101,"select C,J,K,P where C is not null and J > 0"),{"","","",""});IFERROR(query('PI Calcs'!C104:P127,"select C,J,K,P where C is not null and J > 0"),{"","","",""})},2,false)
我通过使用 QUERY 将 3 个范围连接在一起。我正在使用 IFERROR,因为如果任何查询 return 是一个空集,那么我无法将它们合并在一起,失败结果是一个包含 4 个值的空行。
我的困难是从最终集中删除那些空值,因为在对它们进行排序时,每个失败的查询都会得到 1 个空行。我试过使用 FILTER,但我无法引用范围内的列,因为它是动态创建的。
如何从动态创建的范围中过滤掉空白行? 有没有一种方法可以在不返回空范围的情况下查询和连接结果?
为什么不查询您的查询?
=QUERY({IFERROR(query('PI Calcs'!C4:K51,"select C,G,H, K where C is not null and G > 0"),{"","","",""});IFERROR(query('PI Calcs'!C54:P101,"select C,J,K,P where C is not null and J > 0"),{"","","",""});IFERROR(query('PI Calcs'!C104:P127,"select C,J,K,P where C is not null and J > 0"),{"","","",""})},"where Col1 is not null order by Col2 desc",0)
试试这个较短的:
=QUERY(SORT({IFERROR(QUERY('PI Calcs'!C4:K51,
"select C,G,H,K
where C is not null
and G > 0"), {"","","",""});
IFERROR(QUERY({'PI Calcs'!C54:P101; 'PI Calcs'!C104:P127},
"select Col1,Col8,Col9,Col14
where Col1 is not null
and Col8 > 0"), {"","","",""}), 2, 0),
"where Col1 is not null", 0)
甚至更短:
=QUERY({'PI Calcs'!C54:P101; 'PI Calcs'!C104:P127;
{'PI Calcs'!C4:I51, 'PI Calcs'!G4:L51,'PI Calcs'!K4:K51}},
"select Col1,Col8,Col9,Col14
where Col1 is not null
and Col8 > 0
order by Col2 desc", 0)