Double nested IF statement formula in Excel - excel

Good morning,
I would like to set a multiple if statement in Excel.
In row 8 you can see the following formula, which gives an answer in column Q. The answer based on this nested formula is Yes or No.
In row 13 all the cells are empty. Because the nested formula has been dragged down it still shows "No".
I was trying to write some double nested IF statement for this, which could cover the situation when the cells are empty and the Q column can come empty as well as a result.
=IF(OR(M9=" ",OR(N9=" ",OR(O9=" ",OR(P9=" "(IF(OR(M9="No", OR(N9="No", OR(O9="No",OR(P9="No")))))),"Yes","No")," ")
Unfortunately, the formula is not working.
Is it a possibility to add up an additional condition for the nested IF statement in Excel?

Something like:
=IF(COUNTA(M2:P2),<YourFormula>,"")
Where <YourFormula> is a placeholder for whatever formula you are interested in when any value in M2:P2 has a value.

As #JvdV has noted in comment above, your latest formula in comment above is still checking for a space, not a null (empty) cell.
Writing " " will look for a cell that contains a space (someone has hit spacebar). Writing "" will check to see if a cell contains nothing, in other words check to see it is empty.
I also noticed the error in your re-write: You wrapped the logical test within the parenthesis for the COUNTA formula. This is your formula corrected:
=IF(COUNTA(M9:P9)=0,(OR(M9="No",OR(N9="No",OR(O9="No",OR(P9="No"))))),"")
However, each OR statement gives a TRUE or FALSE result and can handle multiple arguments, as indicated by #SolarMike so I think you could probably re-write your formula to as follows to get the same result, if I have understood your requirements correctly:
=IF(COUNTA(M9:P9)=0,IF(COUNTIF(M9:P9,"No")>0,"Yes","No"),"")

Related

How to combine and if statement with a formula to concatenate?

Trying to combine two formulas together but can't figure out how to get them to work. The concatenate formula is
=IF(OR(UPPER(D6)="",UPPER(D6)="N"),A6,A6&" - "&D6)
The formula was created so that if "Y" was entered in a checkbox (yes), then it would combine two different parts to create a result in a separate box. If "N" is entered then it would not concatenate.
The formula was originally
=IF(OR((AND((A6<>""),(D6<>""))),(AND((B6<>""),(D6<>"")))),IF(A6="",B6,A6),"")
I'm trying to figure out how to put a concatenate formula somewhere in this one, haven't had any luck so far.. Thank you.
Most Excel worksheet formulas are not case sensitive, so you don't need UPPER().
Your original formula has a logic error. It can only return TRUE if A is NOT blank. But in the TRUE part, you have another IF statement that is only TRUE if A6 is blank. That situation never happens.
How complicated the formula will be depends on what the logic is. If the result should always be one thing for "n" or a blank input, and another thing for a "y" input, maybe you only need to test for "y" instead of testing for "" and "n".
=if(and(A1="y",B1="y"),X&" - "&Y,X)
If that does not answer your question, please edit your question, provide a data sample and the desired result and explain the logic. Then post a comment, so people get alerted about the update.

Multiple if search statements in excel?

I am trying to convert text of the month to the number
B2 cell:
BirthMonth_Jan
BirthMonth_Feb
BirthMonth_mar
BirthMonth_Apr
BirthMonth_May
BirthMonth_Jun, ect to december
for example, BirthMonth_Jan will output 1 based on the search of Jan, so i can compare this to another set of numbers
I have this, and tried this, but only works with two if statements, is there anyway i can do this with 12?
=(IF(ISNUMBER(SEARCH("sep",B2)),"9")),(IF(ISNUMBER(SEARCH("aug",B2)),"8")),(IF(ISNUMBER(SEARCH("jul",B2)),"7")),(IF(ISNUMBER(SEARCH("jun",B2)),"6")),(IF(ISNUMBER(SEARCH("may",B2)),"5")),(IF(ISNUMBER(SEARCH("apr",B2)),"4")),(IF(ISNUMBER(SEARCH("mar",B2)),"3")),(IF(ISNUMBER(SEARCH("feb",B2)),"2")),(IF(ISNUMBER(SEARCH("jan",B2)),"1"))
I get #Value!
If i try this, it also doesn't work
=IF(ISNUMBER(SEARCH("dec",B2)),"12",IF(ISNUMBER(SEARCH("nov",B2)),"11")),IF(ISNUMBER(SEARCH("DSH_KnowBe4_BirthMonth_Oc",B2)),"10"))
the second option only works with two but if i add more it throws an error
The questioner is trying to obtain a numeral equivalent to a partial month name extracted from a string. There are any number of examples in stackoverflow and the net generally on this theme. What is special in this case is the partial month name in the target cell, and use of the IF statement. The questioner is right to use search since it is not case-sensitive
Two formula are offered:
Formula 1
=(IF(ISNUMBER(SEARCH("sep",B2)),"9")),(IF(ISNUMBER(SEARCH("aug",B2)),"8")),(IF(ISNUMBER(SEARCH("jul",B2)),"7")),(IF(ISNUMBER(SEARCH("jun",B2)),"6")),(IF(ISNUMBER(SEARCH("may",B2)),"5")),(IF(ISNUMBER(SEARCH("apr",B2)),"4")),(IF(ISNUMBER(SEARCH("mar",B2)),"3")),(IF(ISNUMBER(SEARCH("feb",B2)),"2")),(IF(ISNUMBER(SEARCH("jan",B2)),"1"))
The questioner said "I get #Value!"
This is not a surprise because it is essentially a series of nine, self-contained, unrelated if statements, each separated by a comma. It is an invalid statement.
However, if the if statements were nested, then the formula would work. Something along these lines:
=IF(ISNUMBER(SEARCH("jan",B2)),"1",IF(ISNUMBER(SEARCH("feb",B2)),"2",IF(ISNUMBER(SEARCH("mar",B2)),"3")))
Formula 2
=IF(ISNUMBER(SEARCH("dec",B2)),"12",IF(ISNUMBER(SEARCH("nov",B2)),"11")),IF(ISNUMBER(SEARCH("DSH_KnowBe4_BirthMonth_Oc",B2)),"10"))
So close and yet so far... This statement uses the nested approach mentioned above. There is a major typo for the October search (instead of searching for "oct", the formula searches for "DSH_KnowBe4_BirthMonth_Oc") though this doesn't cause the formula to fail.
Failure is caused by two things:
1) The double bracket following "11")) in the "November" search. There should be zero brackets here.
2) The formula needs an additional closing bracket.
Two other things to note:
1) in the event of a match, the value returned is a string not an integer.
2) there's no provision to return a value in the event of a failure to match.
Working IF statement formula
The following formula, consisting of nested IF statements, works as intended by the questioner.
=IF(ISNUMBER(SEARCH("jan",B2)),"1",IF(ISNUMBER(SEARCH("feb",B2)),"2",IF(ISNUMBER(SEARCH("mar",B2)),"3",IF(ISNUMBER(SEARCH("apr",B2)),"4",IF(ISNUMBER(SEARCH("may",B2)),"5",IF(ISNUMBER(SEARCH("jun",B2)),"6",IF(ISNUMBER(SEARCH("jul",B2)),"7",IF(ISNUMBER(SEARCH("aug",B2)),"8",IF(ISNUMBER(SEARCH("sep",B2)),"9",IF(ISNUMBER(SEARCH("oct",B2)),"10",IF(ISNUMBER(SEARCH("nov",B2)),"11",IF(ISNUMBER(SEARCH("dec",B2)),"12",NA()))))))))))))
Note, the formula uses the NA() function to return #N/A if there is no match.
VLOOKUP alternative
Though the above-mentioned formula works, I find it complicated and inflexible. My preference in situations like this is VLOOKUP. My equivalent formula would be:
=VLOOKUP(RIGHT(B2,LEN(B2)-SEARCH("_",B2)),Sheet2!$A$2:$B$13,2,FALSE)
Using January as an example: BirthMonth_Jan, the formula lookup works like this:
RIGHT(B2,LEN(B2)-SEARCH("_",B2))
1) search for the underline character SEARCH("_",B2),
2) deduct the result from the total length LEN(B2)-SEARCH("_",B2) to give the number of characters to the right of the underline.
3) get all the characters to the right of the underline RIGHT(B2,LEN(B2)-SEARCH("_",B2)). This is the lookup value
4) Create a reference table on another sheet (refer screenshot); lookup this table and return column 2 (the number for that month).
5) If there is no valid result, VLOOKUP automatically returns #N/A.
The reference table on a separate sheet:
Not sure what you are trying to do with the formula but if your "BirthMonth_" text is consistent, you can use :
=MONTH(DATEVALUE("1 "&SUBSTITUTE(A12,"BirthMonth_","")&" 2018"))
Having a view of your data and expected result would help if this is not what you're after.
It is seems just possible what you might want is:
=MONTH(MID(B2,SEARCH("BirthMonth_",B2)+11,3)&0)
Returns a Number.

Excel - Minimum and If statement - date error

I am trying to write a formula that checks the status and name to be ongoing and joe blogs (in this example), and once finding a match, will identify the oldest date of a ticket raised.
My formula currently includes:
=MIN(IF('Sheet2'!AA:AA="ONGOING",IF('Sheet2'!Q:Q="Joe Bloggs",'Sheet2'!B18:B49)))
I also tried:
=IF((AND(sheet2!$AA:$AA="ongoing", 'Sheet2'!$Q:$Q="Joe Bloggs")), MIN('Sheet2'!B18:B49),"No")
In Column B contains dates. Q contains names, AA contains the status.
At the moment when this runs I get the result '00/01/1990'.
I have done some checks to find the error, and appears to be around the targets name, as when the second formula is tried, the output is "no". The name is definitely in the Q column, and I have completed other formulas including countifs which have worked perfectly fine.
I have done a lot of searching to find nested ifs and min statements to have no joy , would be grateful of any advice / tips. It may be a simple error to some.
Try entering this as an array formula:
=MIN(IF(sheet2!AA:AA="ongoing",IF(sheet2!q:q="Joe Bloggs",sheet2!B:B)))
FYI I found the solution here.
You will have to apply a date format to the result.
Your first formula works well on my data (as below). If I close the formula with ENTER only, I get the result '37128' and if I close the formula with CTRL+SHIFT+ENTER I get the expected result, '25/08/2001'.
Edit: As #FocusWiz said in the comments, the only major difference (other than different column names) between my formula and yours is the the last range in your formula (B18:B49) is a different sized range to the other two, which are referring to full columns.
*This could be solved either by using the same row range for all three column references (AA18:AA49, Q18:Q49, B18:B49) or referencing the full column range for all three ranges (AA:AA,Q:Q,B:B).
This is your formula I'm talking about:
=MIN(IF('Sheet2'!AA:AA="ONGOING",IF('Sheet2'!Q:Q="Joe Bloggs",'Sheet2'!B18:B49)))
And this is the formula in my workbook F7:
=MIN(IF(B:B="ONGOING",IF(A:A="Joe Bloggs",C:C)))
As you can see in the formula editor, squiggly brackets '{}' show around the formula when it has been closed as an array formula.
If that doesn't work for you, please post some sample data with datatypes so we can help figure out what is causing the lookup value to miss the data.
While I like the technique offered by Patrick (I have frequently forgotten an "else" portion of a formula and gotten "false" as a value in a cell but never thought of a use for that...thank you!), I think this question highlights an issue we all can have with array formulas. As girlvsdata indicates, your original formula:
=MIN(IF(Sheet2!AA:AA="ONGOING",IF(Sheet2!Q:Q="Joe Bloggs",Sheet2!B:B)))
(modified above to be more generic for column B) will also work when entered as an array formula.
What likely happened is that somehow the formula got edited and was not re-entered as an array formula.
While I do not dislike array formulas, I do try to avoid them because I have fat fingers and will frequently mess them up by accidentally hitting the wrong key as I am modifying other cells.
Here is an alternative without using an array formula:
=INDEX(LARGE((Sheet2!Q:Q&Sheet2!AA:AA="Joe bloggs"&"ongoing")*(Sheet2!B:B),COUNTIFS(Sheet2!Q:Q,"Joe Bloggs",Sheet2!AA:AA,"ongoing")),1)
What it does is basically create a candidate date value for every row that has "joe bloggs" and "ongoing" which is equal to the date in column B for all such rows. All other rows get a zero candidate date value. The LARGE function takes the smallest nonzero date by counting the n valid candidates with the COUNTIFS function and taking the nth largest such candidate.

Index Match Works on some cells, not others

I was using this Index Match formula with no issues:
=INDEX('Rain Data For 9 Stations'!A:S,MATCH(RainWICSProximity!J100,'Rain Data For 9 Stations'!A:A,0),INDEX($N$4:$N$12,MATCH(H100,$M$4:$M$12,0)))
I added more data, and it now only returns some values, while returning #N/A for others, even though there is a value to return.
Index returns the value in a range.
What you are doing is =INDEX(MATCH(),INDEX(MATCH())). It works due to some luck, because sometimes the second Index() returns cell with value as well. However, if the second index returns cell with an empty value, then the first index has to return something like =Index(4,0), which is #N/A.
In general, try =Index(Match(),Match()).
To see where exactly the error is, select the cell with the formula, go to the Excel ribbon >Formulas>Evaluate Formula.
Then press a few times Evaluate Formula and see what happens:
See this answer for step-by-step formula evaluation.
#Vityata was correct, Index, Match, Match works wonderfully, also, my original formula does work.
The issue was, I had calculate set to Manual, not auto, in excel settings.
I believe you need to expand your range. I am not real familiar with Index Match but trying to learn to use it more, but I believe it is kind of like VLOOKUP. Your ranges $N$4:$N$12 and $M$4:$M$12 is where it is looking right? If so, those ranges are not expanding even though you added more data. So you need to expand it to like $M$4:$M$100 or whatever. Or expand it to find the last row which is what I usually do. like mine would be "$M$4:$M" & LastRow & "" or something like that.

Is a cell value in column B in column A? (LibreOffice-Calc)

Column A has a sorted-descending list of some bum's Top-250 movies, in the following format: Apocalypse Now (1979)
Column B has a sorted list of My Top-100, in the same format.
Both lists have been copied and pasted into a Notepad text doc to confirm they are similar simple ASCI text – no extra spaces at the end – etc. - and then pasted back into LibreofficeCalc.
I need a function for Column C that shows any of MY movies (B) that he has NOT listed in (A).
Psudo code:
C1 = The cell value in B1 – is it anywhere in A1:A8000? If not – put B1 value into C1, otherwise leave blank.
C2 = The cell value in B2 – is it anywhere in A1:A8000? If not – put B2 value into C2, otherwise leave blank.
Etc.
I have searched and found these functions – none of which work, for whatever reason. I've modified them to 8000 as the upper range which I don't think I'll ever approach.
=IF(ISERROR(MATCH(B1,$A$1:$A$8000,0))=1,B1,"")
=IFERROR(MATCH(B1;$A$1:$A$8000;0);"")
=IFNA(VLOOKUP($B1;$A$1:$A$8000;1;0);"")
=IF(ISNA(VLOOKUP($B1;$A$1:$A$8000;1;0));"";VLOOKUP($B1;$A$1:$A$8000;1;0))
=IF(ISNA(VLOOKUP($B1,$A$1:$A$8000,1,0)),"",VLOOKUP($B1,$A$1:$A$8000,1,0))
=VLOOKUP(B1,$A$1:$A$8000,1,)
=MATCH($B1;$A$1:$A$999;0)
I'd prefer it to be a single cell function, and not VBA.
I actually solved this back in like 2001 using Excel. The trick then was I had to edit the cell and use Ctrl-Shift-Enter to create a “dynamic array”, so the function was bracketed in {} curly brackets. But now I'm using the latest LibreOffice Calc and can't get the ##$# syntax correct.
Thank you!!
Edit NOTE: testing with "A" and "00001" numbers produces very different results. Values have to look like this in both columns:
Alice (1988)
Barfly (1987)
Clueless (1995)
etc.
OK I've tested these in Open Office with the following results:-
=IF(ISERROR(MATCH(B1,$A$1:$A$8000,0))=1,B1,"")
Gives Error 508 because the commas need changing to semicolons.
**=IF(ISERROR(MATCH(B1;$A$1:$A$8000;0))=1;B1;"")**
is fine.
=IFERROR(MATCH(B1;$A$1:$A$8000;0);"")
Gives #Name? because IFERROR isn't recognised.
=IFNA(VLOOKUP($B1;$A$1:$A$8000;1;0);"")
Gives #Name? because IFNA isn't recognised.
=IF(ISNA(VLOOKUP($B1;$A$1:$A$8000;1;0));"";VLOOKUP($B1;$A$1:$A$8000;1;0))
Works but gives the opposite result.
**=IF(ISNA(VLOOKUP($B1;$A$1:$A$8000;1;0));B1;"")**
would be fine.
=IF(ISNA(VLOOKUP($B1,$A$1:$A$8000,1,0)),"",VLOOKUP($B1,$A$1:$A$8000,1,0))
Commas
=VLOOKUP(B1,$A$1:$A$8000,1,)
Commas
=MATCH($B1;$A$1:$A$999;0)
Works but just gives the position of the match.
Probably the easiest way of doing it is:-
**=IF(COUNTIF(A$1:A$8000;B1);"";B1)**
Unfortunately it does seem that strings with brackets in are giving spurious matches in Libre/Open Office. You could get round it by a substitution I guess
=IF(COUNTIF(SUBSTITUTE(SUBSTITUTE(A$1:A$10;"(";"<");")";">");SUBSTITUTE(SUBSTITUTE(B1;"(";"<");")";">"));"";B1)
entered as an array formula and copied (rather than pulled) down or of course global edit all the brackets :-(.
Now that I know the root cause of this thanks to #Lyrl, there is a further option of turning off the regular expressions as suggested or you could escape the brackets:-
=IF(COUNTIF(A$2:A$11;SUBSTITUTE(SUBSTITUTE(B2;"(";"\(");")";"\)"));"";B2)
See documentation on Regex in Open Office here
This should do it,
=IF(ISNUMBER(MATCH(B1,$A$1:$A$8000,0)),"",B1)
Tested formula
=IF(ISNA(MATCH(B1,$A$1:$A$8000,0))=TRUE(),B1,"")

Resources