计算每一行的选定元素并创建一个按计数分组的数组公式
Count selected elements for each line and create an arrayformula that groups by number of counts
我们询问过用户:
What to do with the money?
[ ] paint the bridge
[ ] rebuild the school
[ ] keep the money
[ ] Other : [____________________]
这是包含他们答案的电子表格:
A B
1 Name Choices
2 Lilia paint the bridge, rebuild the school, keep the money
3 Paul rebuild the school, paint the bridge, do something else
4 Margerite keep the money, I don't know, do what you want
5 John paint the bridge
...
800
我想要一个公式来输出每个用户选择的官方选择数量(不包括 other)。
对于前 4 行数据,公式将输出此 table:
D E
Nbr of choices a user made Frequency (Nbr of users who made these choices)
0 0
1 2
2 1
3 1
无法通过单一公式找到正确的方法。对于初学者,我想用“,”拆分(B2:B)的每一行,但找不到将 fn(拆分)应用于公式中每一行的方法...
即使有 800 行数据 (B2:B
),结果 table (D2:E5
) 也总是 4 行长加上标题(和两列宽)
我可以在 C2 中执行此操作,并使用“+”角图标手动复制...
=countif(B2;"*rebuild the school*")+countif(B2;"*keep the money*")+countif(B2;"*paint the bridge*")
然后在E2做:
=arrayformula(countif(C2:C;D2:D5))
但我想在一个公式中生成 table 个频率,而无需任何手动操作(没有 C
列)。
所以我正在寻找一种方法 "map" 每行的第一个函数,把它放在第二个 fn 中。
Akshin Jalilov 的回答已解释
这是 Akshin Jalilov 的回答,但更短(并带有国际符号)
=ARRAYFORMULA(COUNTIF(ARRAYFORMULA(IF(B2:B="";;COUNTIF(ARRAYFORMULA
(IFERROR(IF(FIND("paint the bridge";B2:B);Row(B2:B);0)));"="&row(B2:B))
+COUNTIF(ARRAYFORMULA(IFERROR(IF(FIND(
"rebuild the school";B2:B);Row(B2:B);0)));"="&row(B2:B))
+COUNTIF(ARRAYFORMULA(IFERROR(IF(FIND(
"keep the money";B2:B);Row(B2:B);0)));"="&row(B2:B))));"="&D2:D5))
第一步:
IF(FIND("rebuild the school";B2:B);Row(B2:B);0)
这意味着,对于每一行 (B2:B
) 找到 "rebuild the school"。如果找到了,return行号,否则,return0.
第二步:
=ARRAYFORMULA(IFERROR(Step1))
将其包装在 ARRAYFORMULA 中,以便您 return 每行的结果。
我认为 IFERROR 是为了防止错误停止进程。
第三步:
=ARRAYFORMULA(IF(B2:B="";;COUNTIF(ARRAYFORMULA(IFERROR(IF(FIND("paint the bridge";B2:B);Row(B2:B);0)));"="&row(B2:B))+countif(Step2)+countif(ARRAYFORMULA(IFERROR(IF(FIND("keep the money";B2:B);Row(B2:B);0)));"="&row(B2:B))))
这将计算每个用户的有效投票。这相当于我手动过程中提到的 C2 公式。但它现在是单一全球公式的一部分吗?
第四步:
最后,公式的其余部分计算每个投票计数可能性的频率。
我知道这个公式很大,但这是我最接近你想要的。
现在为了简单起见,将您的响应范围命名为 "Responses"。我假设它是 B2:B。
公式如下:
=ARRAYFORMULA(Countif(ARRAYFORMULA(IF(Responses="",,COUNTIF(VLOOKUP(row(Responses),({ARRAYFORMULA(Row(Responses)),ARRAYFORMULA(IFERROR(IF(FIND("paint the bridge",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("rebuild the school",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("keep the money",Responses),Row(Responses),0)))}),2),"="&row(Responses))+COUNTIF(VLOOKUP(row(Responses),({ARRAYFORMULA(Row(Responses)),ARRAYFORMULA(IFERROR(IF(FIND("paint the bridge",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("rebuild the school",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("keep the money",Responses),Row(Responses),0)))}),3),"="&row(Responses))+COUNTIF(VLOOKUP(row(Responses),({ARRAYFORMULA(Row(Responses)),ARRAYFORMULA(IFERROR(IF(FIND("paint the bridge",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("rebuild the school",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("keep the money",Responses),Row(Responses),0)))}),4),"="&row(Responses)))),"="&D2:D5))
Here 是一个示例,说明它是如何工作的。我不确定你到底想要哪一个,所以都添加了
我们询问过用户:
What to do with the money?
[ ] paint the bridge
[ ] rebuild the school
[ ] keep the money
[ ] Other : [____________________]
这是包含他们答案的电子表格:
A B
1 Name Choices
2 Lilia paint the bridge, rebuild the school, keep the money
3 Paul rebuild the school, paint the bridge, do something else
4 Margerite keep the money, I don't know, do what you want
5 John paint the bridge
...
800
我想要一个公式来输出每个用户选择的官方选择数量(不包括 other)。
对于前 4 行数据,公式将输出此 table:
D E
Nbr of choices a user made Frequency (Nbr of users who made these choices)
0 0
1 2
2 1
3 1
无法通过单一公式找到正确的方法。对于初学者,我想用“,”拆分(B2:B)的每一行,但找不到将 fn(拆分)应用于公式中每一行的方法...
即使有 800 行数据 (B2:B
),结果 table (D2:E5
) 也总是 4 行长加上标题(和两列宽)
我可以在 C2 中执行此操作,并使用“+”角图标手动复制...
=countif(B2;"*rebuild the school*")+countif(B2;"*keep the money*")+countif(B2;"*paint the bridge*")
然后在E2做:
=arrayformula(countif(C2:C;D2:D5))
但我想在一个公式中生成 table 个频率,而无需任何手动操作(没有 C
列)。
所以我正在寻找一种方法 "map" 每行的第一个函数,把它放在第二个 fn 中。
Akshin Jalilov 的回答已解释
这是 Akshin Jalilov 的回答,但更短(并带有国际符号)
=ARRAYFORMULA(COUNTIF(ARRAYFORMULA(IF(B2:B="";;COUNTIF(ARRAYFORMULA
(IFERROR(IF(FIND("paint the bridge";B2:B);Row(B2:B);0)));"="&row(B2:B))
+COUNTIF(ARRAYFORMULA(IFERROR(IF(FIND(
"rebuild the school";B2:B);Row(B2:B);0)));"="&row(B2:B))
+COUNTIF(ARRAYFORMULA(IFERROR(IF(FIND(
"keep the money";B2:B);Row(B2:B);0)));"="&row(B2:B))));"="&D2:D5))
第一步:
IF(FIND("rebuild the school";B2:B);Row(B2:B);0)
这意味着,对于每一行 (B2:B
) 找到 "rebuild the school"。如果找到了,return行号,否则,return0.
第二步:
=ARRAYFORMULA(IFERROR(Step1))
将其包装在 ARRAYFORMULA 中,以便您 return 每行的结果。 我认为 IFERROR 是为了防止错误停止进程。
第三步:
=ARRAYFORMULA(IF(B2:B="";;COUNTIF(ARRAYFORMULA(IFERROR(IF(FIND("paint the bridge";B2:B);Row(B2:B);0)));"="&row(B2:B))+countif(Step2)+countif(ARRAYFORMULA(IFERROR(IF(FIND("keep the money";B2:B);Row(B2:B);0)));"="&row(B2:B))))
这将计算每个用户的有效投票。这相当于我手动过程中提到的 C2 公式。但它现在是单一全球公式的一部分吗?
第四步: 最后,公式的其余部分计算每个投票计数可能性的频率。
我知道这个公式很大,但这是我最接近你想要的。 现在为了简单起见,将您的响应范围命名为 "Responses"。我假设它是 B2:B。
公式如下:
=ARRAYFORMULA(Countif(ARRAYFORMULA(IF(Responses="",,COUNTIF(VLOOKUP(row(Responses),({ARRAYFORMULA(Row(Responses)),ARRAYFORMULA(IFERROR(IF(FIND("paint the bridge",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("rebuild the school",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("keep the money",Responses),Row(Responses),0)))}),2),"="&row(Responses))+COUNTIF(VLOOKUP(row(Responses),({ARRAYFORMULA(Row(Responses)),ARRAYFORMULA(IFERROR(IF(FIND("paint the bridge",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("rebuild the school",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("keep the money",Responses),Row(Responses),0)))}),3),"="&row(Responses))+COUNTIF(VLOOKUP(row(Responses),({ARRAYFORMULA(Row(Responses)),ARRAYFORMULA(IFERROR(IF(FIND("paint the bridge",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("rebuild the school",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("keep the money",Responses),Row(Responses),0)))}),4),"="&row(Responses)))),"="&D2:D5))
Here 是一个示例,说明它是如何工作的。我不确定你到底想要哪一个,所以都添加了