【发布时间】:2023-03-28 04:24:01
【问题描述】:
我们已询问用户:
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
我想要一个公式来输出每个用户选择的官方选择的数量(不包括其他)。
使用前 4 行数据,公式将输出此表:
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),结果表 (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))
但我想在一个公式中生成频率表,无需任何手动操作(没有C 列)。
所以我正在寻找一种将第一个函数“映射”到每一行的方法,将其放在第二个 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) 找到“重建学校”。如果找到,返回行号,否则返回0。
第二步:
=ARRAYFORMULA(IFERROR(Step1))
将其包装在 ARRAYFORMULA 中,以便返回每一行的结果。 我认为 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 公式。但它现在是单一全局公式的一部分吗?
第四步: 最后,公式的其余部分计算每个投票计数可能性的频率。
【问题讨论】:
标签: google-sheets formulas array-formulas