Trying to make an if statement that will return 4 outcomes based on the contents of the cell
If the cell is "Yes", "No", "NA", "Unknown", to return 0, 1, 2, 3 respectively.
I can use If(A1="Yes", 0,1) but not sure how to handle the other conditions
SWITCH would be a better call:
=SWITCH(A1,"Yes",0,"No",1,"N/A",2,"Unknown",3,"I'-'I")
Please try:
=IF(A1="Yes",0,IF(A1="No",1,IF(A1="Unknown",3,2)))
Anything other than the given selection in A1 (and not an error) and the formula would return 2.
The concept you are asking for in the Google Docs Editors help center is called "nested function". This concept refers to using a function as a parameter of another function.
The syntax for IF is
IF(logical_expression, value_if_true, value_if_false)
You could replace logical_expression, value_if_true and/or value_if_false with another IF. For this specific case, try
=IF(A1="Yes",0,IF(A1="No",1,IF(A1="NA",2,IF(A1="Unknown",3,NA())))
#N/A will be returned if A1 contains an unexpected value.
Reference
Add formulas and functions to a spreadsheet
Related
I have been looking for a solution to this for quite a few hours, but unfortunately I appear to be stuck. I am trying to automatically input data based on another sheet with three possible options. DEADLINE, PMC or FMC, but it keeps crashing with if it can't find the first result. It will say #N/A, and tells me it can't find the first value. Why doesn't it check for the other values?
=IFS((MATCH(J8,Faults!F3:F9,0)),"DEADLINE",(MATCH(J6,Faults!F3:F9,0)),"PMC",(MATCH(J4,Faults!F3:F9,0)),"FMC")
Thanks in advance
MATCH does not return TRUE or FALSE. It either returns a number (the position within the range) or a #N/A error.
IFS will throw an error and stop processing just as a nested IF will. Wrap all the match functions in ISNUMBER to bypass thrown #N/A errors on no match.
=IFS(isnumber(MATCH(J8, Faults!F3:F9, 0)),"DEADLINE", isnumber(MATCH(J6, Faults!F3:F9, 0)), "PMC", isnumber(MATCH(J4, Faults!F3:F9, 0)), "FMC", true, "other")
I've added a default of Other if none of the three matches are found.
background info - not important
I realise I need improvement on understanding logic and understanding documentation when playing around with Android apps. So, I thought I'll switch to Google Sheets in the hope of some basic practice in a context I might find easier to understand.
question
I've set up a Google Sheet:
https://docs.google.com/spreadsheets/d/1T7q_CGMFObxS_0DGikUdSdLTf97XmEPXY0S7yItuA5Y/edit?usp=sharing
I would like Column B to:
display "Folder1" if "Black" is found in the adjacent Column A cell.
display "Folder2" if "Blue" is found in the adjacent Column A cell.
display "Folder3" if "Green" is found in the adjacent Column A cell.
and to then be able to add more conditions.
My formula for Column B is currently:
=ARRAYFORMULA(
IFS(
find("Black", A2:A,1)>0,"Folder1",
find("Blue", A2:A,1)>0,"Folder2",
find("Green", A2:A,1)>0,"Folder3")
)
Which is only meeting the first condition "Folder1" if "Black" is found and not continuing with the rest of the if clauses.
I think I have nested it correctly though because all of the IFS() are at the same level with their corresponding find() within. And, I have two closing brackets which close the IFS and the ARRAYFORMULA.
Am I just simply not using the right kind of functions for what I'd like to do?
Thank you for your suggestions on how I can solve this!
The problem is that find() only returns a number > 0 if it actually finds a match. Otherwise it returns an error which you can't test for explicitly.
You can fix you code like this:
=ARRAYFORMULA(
IFS(
isnumber(find("Black", A2:A,1)),"Folder1",
isnumber(find("Blue", A2:A,1)),"Folder2",
isnumber(find("Green", A2:A,1)),"Folder3")
)
Now we can test that what find() returns is an number and the code will work!
Obviously, I put on multiple lines for clarity.
I am trying to change the value of cell B1 depending on if cell A1's value is found in another spreadsheet. If there is a match, I want the cell to say "banned". If A1 isn't found in the other spreadsheet, I want it to say "active'.
I've been playing around with this
=if((VLOOKUP(A3,IMPORTRANGE("https://docs.google.com/xyz","ALL BANNED ACCOUNTS!$G$2:$G$300"),1,false))=A3,"Banned","Active")
and can only get it to return "Banned". If there is no match, it always returns #N/A.
How can I remedy this?
Thanks!
Try changing "FALSE" TO "TRUE". I have found that VLOOKUP behaves erratically, and simply changing the [is_sorted] value helps.
Also, this may or may not make a difference, but you have an extra set of parentheses in your formula:
=if(VLOOKUP(A3,IMPORTRANGE("https://docs.google.com/xyz","ALL BANNED
ACCOUNTS!$G$2:$G$300"),1,false)=A3,"Banned","Active")
This is an old question, but in case it helps someone, since you are using VLOOKUP in one column, the only choices are that it equals A3, or that it isn't found, and if it isn't found, VLOOKUP fails, rather than equaling something else. Therefore, you can use this formula:
=iferror(if(VLOOKUP(A3,IMPORTRANGE("https://docs.google.com/xyz","ALL BANNED
ACCOUNTS!$G$2:$G$300"),1,false)=A3,"Banned","irrelevant"),"Active")
Note that "irrelevant" can be changed to anything, i.e. 0, etc. This result will never happen, as if VLOOKUP isn't equal to the search cell (in this case, A3), it will throw an error. So, "Active" as the result if there's an error will show rather than the value if VLOOKUP is false (since it can't be).
Hopefully this helps someone!
I can't find an example close enough to this one on StackOverflow so here goes:
I want to return a message "Type?" if cell X is blank and cell Y has any text. But I'm trying to nestle it into an existing set of IFs.
Existing :
=IF($G241="Evo";M241*L241;IF($G241="Free";M241*L241;IF($G241="GN";M241*L241))))
Nestling this into the above:
=IF(AND(NOT(ISBLANK($J234));ISBLANK(G234));"Type?";"OK")
I tried this but it returns FALSE, maybe due to the AND I'm using, which I need since I'm creating a return based on two cells two cells.
=IF($G240="Evo";M240*L240;IF(AND(NOT(ISBLANK($J240));ISBLANK(G240);"Type?";"OK");IF($G240="Free";M240*L240;IF($G240="GN";M240*L240))))
getting Error:
AND expects boolean values. But 'Type?' is a text and cannot be coerced to a boolean.
IF(and(isblank(cell x),iferror(isstring(cell y),false)),"Type?","OK")
That should do it for you I think. you will need to replace cell x and cell y with the appropriate references. The iferror statement is there to catch what happens when evaluating a blank cell y.
The problem with this formula
=IF($G240="Evo";M240*L240;IF(AND(NOT(ISBLANK($J240));ISBLANK(G240);"Type?";"OK");IF($G240="Free";M240*L240;IF($G240="GN";M240*L240))))
is you are trying to check G240 for different values when it cant. Lets simplify your formula. We will replace your empty cell check with FORMULA 1
=If($G240="EVO", Do True Condition, Do Formula 1, IF(G$240=Free, Do Free True Condition, Do Free False Condition)
The problem is since you already did something (Formula 1) when G240 = "EVO", you cant start another check on what G240 after the fact with the way you have embedded your formula. a batter way of thinking of it is how to do a second check when G240="EVO" is false. Remember the general format of an if statement is:
IF(CONDITION,True Result, False Result)
There are only 3 things that go into an if statement. you tried putting in 3.
Try rearranging to this:
=If($G240="EVO", Do True Condition, IF(SOME CHECK to determine DO FOMULA 1 or CHECK for G240 = FREE, Do Formula 1, IF(G$240=Free, Do Free True Condition, Do Free False Condition)))
Basically break down what you want to check for in G240 and do it in sequence with your IF statement. Right now with what you have written, I cant tell how you want to determine if you want to run your formula 1 or if you want to check if G240="free" since you have two different outcomes if G240="Free"/
OK I think i found the issue. The IF(AND(NOT(ISBLANK works on it's own since there are no other IFs in the formula. I do want to test two different cells for text(letters) in order to show a warning if one cell was blank while the other not. But as soon as you insert the (AND into a string of multiple IFs it doesn't work.
Simply removing the (AND was all I needed to do. Another way to achieve a test for more than one blank cell was to simply add multiple IF(ISBLANKs.
EG: =IF(ISBLANK(A1)+IF(ISBLANK(A2)>2;condition true;condition false)
ForwardEd thanks very much for your help!
Regards
I asked for help on another formula earlier which has lead to another head scratcher for me. I'm sure there is probably a way to use IFERROR somewhere in the formula below, but I can't seem to figure out where. I have a few columns returning #N/A that I just need to be blank.
Everything is working how it should except for the error. I have another formula feeding off of the results of this formula that I need to populate either Y or N based on the results. The #N/A is throwing some of them off.
=IF(J2="",VLOOKUP(B2,Sheet1!B:F,5,FALSE),"PICKED UP")
Just wrap it like this:
=IF(J2="",IFERROR(VLOOKUP(B2,Sheet1!B:F,5,0),"Error msg here"),"PICKED UP")
IFERROR will evaluate the first expression (here, it's the VLOOKUP) and if it returns an error, it will return the second part of the formula, which is Error msg here in this case. Change it to whatever you want to.
Also, you can use 0 to mean FALSE in excel (and 1 to mean TRUE).
=IF(J2="", IF(ISNA(VLOOKUP(B2,Sheet1!B:F,5,FALSE)), "", VLOOKUP(B2,Sheet1!B:F,5,FALSE)),"PICKED UP")