Search code examples
if-statementgoogle-sheets

Issues with Multiple IF Formulas in one cell in Google Sheets returning a Formula Parse Error


I'm creating a small risk calculator in Google Sheets. You select two word-based values from a drop down menu and that should spit out the risk "score" in a third column that consists of adding two numerical values together. It looks like this:

[redacted image]

I thought using this should work to get the first number.

=IF(C7="Frequently"; 4; 0), IF(C7="Likely"; 3; 0), IF(C7="Occasionally"; 2; 0), IF(C7="Seldom"; 1; 0)

It works to get the first number, but when I put the second IF in, it starts to give me an error. Is it because it can't put both a four and a zero in at once? So it's not able to return a value? If that's the issue, how do I fix this?

I assumed it'd differentiate between the logical_expression.


Solution

  • The syntax of the IF function is:

    IF(condition; value_if_true; value_if_false)
    

    So the correct way to write that formula is:

    =IF(C7="Frequently";4;
       IF(C7="Likely";3;
         IF(C7="Occasionally";2;
           IF(C7="Seldom";1;0))))
    

    However, I recommend using the SWITCH function as it's more concise and it doesn't require the repetition of the cell reference (C7):

    =SWITCH(C7;"Frequently";4;"Likely";3;"Occasionally";2;"Seldom";1;0)