如何根据垂直组合查询空白行过滤此条件?

问题描述 投票:0回答:2

我使用它根据条件成功(或几乎)将多个列查询到 01 中。然而,这显示了一个我似乎无法摆脱的空白行。

=iferror({
query({Orders!A:FF}, "select Col144 where Col7 matches '"& P4 &"' and not Col144 contains '#N/A' and not Col144 matches '-' and Col144 is not null");
query({Orders!A:FF}, "select Col151 where Col7 matches '"& P4 &"' and not Col151 contains '#N/A' and not Col151 matches '-' and Col151 is not null");
query({Orders!A:FF}, "select Col162 where Col7 matches '"& P4 &"' and not Col162 contains '#N/A' and not Col162 matches '-' and Col162 is not null")
},"")

我尝试在查询条件集中过滤它,但它仍然显示。 这是当前结果,始终带有空白行:

如何实现?

这里有一些用于测试的模拟数据

google-sheets google-sheets-formula
2个回答
1
投票

请参阅名为 MK.Help 的新选项卡,您将在其中找到此公式仅显示方差为 2 的项目。

=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(D2:I2&"|"&A4:A6&"|"&B4:B6&"|"&D4:I6),"|",0,0),"where Col2 = 2"))

自从几年前发现隐藏在 Google Sheets 后端的 Flatten 函数以来,查询(split(Flatten()技术已成为“逆透视”数据的最常见方法。


0
投票

如果我正确理解你的问题,你只想从返回的查询中删除空白行。您可以尝试添加另一个查询而不是过滤器来删除空白。

从您的示例表中,我编辑了现有公式

尝试:

=QUERY({QUERY({D1:G10},"select Col2 where Col1 matches '"&B2&"'",0);QUERY({D1:G10},"select Col3 where Col1 matches '"&B2&"'",0);QUERY({D1:G10},"select Col4 where Col1 matches '"&B2&"'",0)},"Select Col1 where Col1 is not NULL")

结果:

让我知道这是否适合您。

© www.soinside.com 2019 - 2024. All rights reserved.