![](/img/trans.png)
[英]How to translate COUNTIFS formula in ARRAYFORMULA to automatically insert the formula in each row
[英]How to translate QUERY formula in ARRAYFORMULA to automatically populate the QUERY for each row
使用我的查詢公式,我想計算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列。 如何更改將檢查每一行的公式?
在另一個論壇上,我得到了答案。 對於任何有興趣的人:
=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")))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.