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

57 views Asked by At

[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.

2

There are 2 answers

1
milklizard On BEST ANSWER

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")
4
rockinfreakshow On

Can you try:

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