在Google Sheets中,使用IF语句将年龄分类为不同组的正确语法是什么?

huangapple go评论104阅读模式
英文:

What is the correct syntax to classify ages into groups using IF statements in Google Sheets?

问题

=IF (H19<20, "0-19", IF ((H19>=20 AND H19<40), "20-39", IF ((H19>=40 AND H19<60), "40-59", IF ((H19>=60 AND H19<70), "60-69", IF (H19>=70, ">= 70", "WRONG")))))

英文:

[Why am i getting "formula parse error" when I try to classify the ages (column H) into groups using the following formula? And is there a better way? Thanks for your assistance:

=IF (H19<20, “0-19”, IF ((H19>=20 AND H19<40), “20-39”, IF ((H19>=40 AND H19<60), “40-59”, IF ((H19>=60 AND H19<70), “60-69”, IF (H19>=70, ">= 70", “WRONG”)))))

I was expecting to output the Age column into strings based on my category definitions.

答案1

得分: 3

=let(Σ,{0 ,"0-19";
20 ,"20-39";
40 ,"40-59";
60 ,"60-69";
70 ,">=70"},
vlookup(H19,Σ,2,1))

  • 使用***VLOOKUP***的近似匹配能力
英文:

Can you try:

=let(Σ,{0  ,&quot;0-19&quot;;
        20 ,&quot;20-39&quot;;
        40 ,&quot;40-59&quot;;
        60 ,&quot;60-69&quot;;
        70 ,&quot;&gt;=70&quot;},
     vlookup(H19,Σ,2,1))
  • uses VLOOKUP approx. match capability

答案2

得分: 1

The portions that you have formatted as (H19>=20 AND H19<40) should be changed to AND(H19>=20, H19<40). Your final formula should then be:

=IF(H19<20, "0-19",
  IF(AND(H19>=20, H19<40), "20-39",
  IF(AND(H19>=40, H19<60), "40-59",
  IF(AND(H19>=60, H19<70), "60-69",
  IF(H19>=70, ">= 70", "WRONG")))))

Alternatively:

=IFS(OR(NOT(ISNUMBER(H19)),H19<0), "WRONG",
  H19<20, "0-19",
  AND(H19>=20, H19<40), "20-39",
  AND(H19>=40, H19<60), "40-59",
  AND(H19>=60, H19<70), "60-69",
  H19>=70, ">= 70")
英文:

The portions that you have formatted as (H19&gt;=20 AND H19&lt;40) should be changed to AND(H19&gt;=20, H19&lt;40). Your final formula should then be:

=IF(H19&lt;20, “0-19”,
  IF(AND(H19&gt;=20, H19&lt;40), “20-39”,
  IF(AND(H19&gt;=40, H19&lt;60), “40-59”,
  IF(AND(H19&gt;=60, H19&lt;70), “60-69”,
  IF(H19&gt;=70, &quot;&gt;= 70&quot;, “WRONG”)))))

Alternatively:

=IFS(OR(NOT(ISNUMBER(H19)),H19&lt;0), &quot;WRONG&quot;,
  H19&lt;20, &quot;0-19&quot;,
  AND(H19&gt;=20, H19&lt;40), &quot;20-39&quot;,
  AND(H19&gt;=40, H19&lt;60), &quot;40-59&quot;,
  AND(H19&gt;=60, H19&lt;70), &quot;60-69&quot;,
  H19&gt;=70, &quot;&gt;= 70&quot;)

huangapple
  • 本文由 发表于 2023年6月2日 02:40:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76384804.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定