如何在ARRAYFORMULA中翻译QUERY公式以自动填充每行的QUERY

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

使用我的查询公式,我想计算A列中某个字符串的所有重复出现(例如Apple),同时检查是否在出现重复字符串的同一行上,列B不为空。根据计数是否大于0,我想在每行的C列中显示一条消息。

在查询的WHERE子句中,我引用了要显示消息的A列的行号,如下所示:

…where A = '"&A1&"'…
…where A = '"&A2&"'…
…where A = '"&A3&"'…

=IF(IFERROR(QUERY($A:$B;"select COUNT(A) where A = '"&A1&"' and B is not
null LABEL COUNT(A) ''";0)) > 0;"B is not empty for duplicate strings";"B 
is empty for duplicate strings").  

结果应该是这样的:

+---+---------+---+--------------------------------------+--+
|   |    A    | B |                  C                   |  |
+---+---------+---+--------------------------------------+--+
| 1 | Apple   | 1 | B is not empty for duplicate strings |  |
| 2 | Apple   |   | B is not empty for duplicate strings |  |
| 3 | Orange  |   | B is empty for duplicate strings     |  |
| 4 | Orange  |   | B is empty for duplicate strings     |  |
+---+---------+---+--------------------------------------+--+

我想将此公式转换为数组公式并将其放入标题中,以便公式自动扩展。

到目前为止我尝试过的:

={"YOUR HEADER";ARRAYFORMULA(IF(IFERROR(QUERY($A:$B;"select COUNT(A) 
where A = '"&A2&"' and B is not null LABEL COUNT(A) ''";0)) > 0;"B is 
not empty for duplicate strings";"B is empty for duplicate strings"))}

这将仅适用于第二行,因为我的查询引用了列A2。如何更改它将检查每一行的公式?

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

在另一个论坛上,我得到了答案。对于任何有兴趣的人:

=ArrayFormula(IF(A2:A="";"";IF(QUERY(ArrayFormula(COUNTIF(QUERY(A2:B;"select A,
count(A) where B is not null group by A label count(A)''");A2:B));"select 
Col1")>0;"B is not empty for duplicate strings";"B is empty for duplicate strings")))
© www.soinside.com 2019 - 2024. All rights reserved.