1

I have a very simple SWITCH statement in Google Sheets:

=switch(
    D2,"",B2,
    D2,"A","A",
    D2,"B","B",
    "Default"
    )

If I put any non-blank value in D2, I always get A back, even if I put B or anything else (one or more characters). If I leave D2 blank, I correctly get B2's value. It's as if any non-blank string is equal to "A" as SWITCH does the comparison. But that's certainly not what the documentation and many other websites offering examples of SWITCH say should happen.

Is this a bug in Sheets or what am I misunderstanding?

My real use case is far more than 3 cases, so please don't advise me to use nested IFs instead.

1 Answer 1

2

SWITCH function in google sheets.

The switch function uses the following syntax:

SWITCH(expression, case1, value1, [case2, value2, ...], [default])

So remove your extra D2 in the function and it should work.

=SWITCH(
    D2,"",B2,
    "A","A",
    "B","B",
    "Default"
    )

You can also use a range in place of the first argument, in case you were dragging down the formula.

1
  • Duh, I guess I was seeing what I wanted to see, as I need different expressions per each case. Not possible. Thank you very much! Apr 29, 2022 at 0:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.