简体   繁体   中英

Google Sheets, Multiple IF, AND Statements with point ranges

So I am using a google spreadsheet to track students points on a math test. I give them a grade based on their points and there end up being a lot of alternatives. We have levelled points so the information below shows first the grade they would get then the total points they got and then the C or higher level points they have.

E   5 pts

D   7 pts 2 c+

C   9 pts 3 c+

B   11pts 5 c+ 

A   13 pts 6 c+

Currently, I have a Google sheet that tallies up there points when I input and I have a column for total points and C or higher points.

I was attempting to do it with multiple IF and AND statements but it isn't working correctly (I end up with the wrong Grade coming out)

Here is the code I tried:

=If(W3<5,"F",IF(AND(W3>=5,X3<2),"E",If(AND(W3>=7,1<X3<3),"D",If(AND(7<W3<9,X3>=2),"D",IF(AND(W3>=9,2<X3<5),"C",IF(AND(8<W3<11,X3>=3),"C",IF(AND(W3>=11,4<X3<6),"B",IF(AND(10<W3<13,X3>=5),"B","A"))))))))

I'm hoping there is an easier way to do this or someone spots my mistake. It isn't the end of the world if it isn't possible because I can just look at the results but it is more fun to be able to figure out how to have it down automatically.

ARRAYFORMULA variant of this solution which will auto-populate grades for all rows. can be pasted in any column on the second row

={"GRADE"; 
 ARRAYFORMULA(IF(LEN(W3:W),
              IF(W3:W<5,  "F",
              IF(W3:W<7,  "E",
              IF(X3:X<2,  "E",
              IF(W3:W<9,  "D",
              IF(X3:X<3,  "D",
              IF(W3:W<11, "C",
              IF(X3:X<5,  "C",
              IF(W3:W<12, "B",
              IF(X3:X<6,  "B", "A"))))))))), ))}

Google sheets doesn't like logical expressions with more than one operator (eg, 1<X3<2 ), so those will need to be broken up into two expressions with the AND() operator (eg, AND(1<X3, X3<2) ).

There seem to be some holes in the possible value combinations though, which become obvious if you graph them out:

在此处输入图片说明

A simpler way to write the logic would be to take a kind of "weaving" pattern to each successive conditional, as illustrated below. This approach lets us avoid having to describe ranges or use AND() operators, and ensures there are no combinations that are undefined.

在此处输入图片说明

This approach can be described in pseudocode as:

1:  if      (W3 < 5)  F
2:  else if (W3 < 7)  E
3:  else if (X3 < 2)  E
4:  else if (W3 < 9)  D
5:  else if (X3 < 3)  D
6:  else if (W3 < 11) C
7:  else if (X3 < 5)  C
8:  else if (W3 < 12) B
9:  else if (X3 < 6)  B
10: else              A

The Google Sheets formula for this would be:

=IF(W3<5,"F",IF(W3<7,"E",IF(X3<2,"E",IF(W3<9,"D",IF(X3<3,"D",IF(W3<11,"C",IF(X3<5,"C",IF(W3<12,"B",IF(X3<6,"B","A")))))))))

One method is to use the AND operator repeatedly to limit the value range. If the answer can be further simplified, please kindly share in this post.

The following code demonstrates how to use AND operators repeatedly to limit the value range:

=If(W3<5,"F",IF(AND(W3>=5,X3<2),"E",If(AND(W3>=7,1<X3<3),"D",If(AND(AND(6<W3,W3<9),X3>=2),"D",IF(AND(W3>=9,AND(2<X3,X3<5)),"C",IF(AND(AND(8<W3,W3<11),X3>=3),"C",IF(AND(W3>=11,AND(4<X3,X3<6)),"B",IF(AND(AND(10<W3,W3<13),X3>=5),"B",IF(AND(W3>=13,X3>=6),"A","undefined")))))))))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM