I am trying to use the value that returned true later on in an equation but am finding it difficult, if not impossible, to do so. This is what my formula looks like:
=IF(SUMPRODUCT(--ISNUMBER(SEARCH({"Application","Account","Machine"}, H5))),
INDEX(Sheet1!N$2:N$7,
MATCH(<term that made the SEARCH function true,Sheet1!M$2:M$7,0)), "")
I am trying to search a cell for a series of words, and if one of those words is found, use that word in an INDEX-MATCH search. Is there a way to do this or do I need to break my work up into two steps?
I think that you are after this:
=IFERROR(INDEX(Sheet1!N:N, MATCH(
INDEX({"Application","Account","Machine"},
MATCH(TRUE,ISNUMBER(SEARCH({"Application","Account","Machine"},H5)),0)),
Sheet1!M:M,0)), "")
Note that the inner INDEX/MATCH is what you were looking for, that is, returns from the array the keyword that exists inside the H5 sentence.
Related
I have a spreadsheet in which I would like to return the text of all cells in MyTable field "Result" in which the corresponding text in MyTable field "Query" matches a string in $C$1, as a list. I want to do this using formulas. I know that my formula will need to have the following form:
=INDEX(MyTable[Result],SMALL(IF(MyTable[Query]=C1,ROW(MyTable[Result]),""),___))
The issue is that I'm not sure what should go in the ___. I want my formula to return strings from all relevant cells, not just a fixed number of cells, because I don't know now many cells match the criteria. As far as I understand, SMALL throws an error if the number provided as the last argument exceeds the number of non-empty strings returned by the IF function. Is there any way around this?
You k argument can be an array. And the upper bounds can probably be calculated using COUNTIF in your case.
Arrays can be constructed in a variety of ways.
One way (not the most efficient) would be something like:
=row(indirect("1:" & countif(MyTable[Query],C1)))
You can also use the INDEX function to construct the array, and, if speed is an issue, this would be better as it is a non-volatile function.
I'm trying to create a formula that will search a cell for the following words.. "Other" & "Repair" if either of these words are found I want it to be categorized as the word that is found. If none of these words are found I want the formula to Vlookup another column to then categorize it.
I got the formula to work for one search word, I cant figure out how to do it with two search words.
below is the formula I used for one word search criteria.
=IF(ISNUMBER(SEARCH("REPAIR",B9089)),"REPAIR",VLOOKUP(E9089,Key!$D:$E,2,0))
This is what I tried doing for the two search words but it breaks at the end for the true / flase statement
=IF(OR(ISNUMBER(SEARCH("REPAIR",B9090)),ISNUMBER(SEARCH("OTHER",B9090))),"REPAIR""OTHER",VLOOKUP(E9090,Key!$D:$E,2,0))
If you need to search for two values and the values returned, an OR statement will not work. Since it will only return true or false to an IF statement, and the IF will then return only one value. Instead, you can nest two IF statements inside each other for each of the values you need to find. Try the following formula:
=IF(ISNUMBER(SEARCH("Repair",B9089)),"Repair",IF(ISNUMBER(SEARCH("Other",B9089)),"Other",VLOOKUP(E9089,Key!$D:$E,2,0)))
(I am assuming your references and the Vlookup statement are correctly written by yourself)
I think you'll need nested IF statements, like this:
=IF(ISNUMBER(SEARCH("REPAIR",B9089)),"REPAIR", IF(ISNUMBER(SEARCH("OTHER",B9089)),"OTHER",VLOOKUP(E9089,Key!$D:$E,2,0))
What this does is first check if "REPAIR" is part of the speciified cell's value, if it isn't it checks if the cell value contains "OTHER", and if that is not the case it performs the desired VLOOKUP.
Please not that this is doable for two conditions, but if it starts getting to higher numbers you should consider writing a custom function in VBA.
I came across an interesting question regarding excel and I would like to know the theoretical background of it, google didn't help...
Lets say you want to sum the values of column B if the date (stored in column A) is this week. So what you do is =SUMIF(A:A;">"&TODAY()-8;B:B)
I am interested in the explanation why there is a need for the " " and the & symbols.
If I use an if function, there is no need, eg.: =IF(A3>TODAY()-8;TRUE;FALSE) works perfectly.
So why is it that
=SUMIF(A:A;>TODAY()-8;B:B) ----> formula parse error
=IF(A3>TODAY()-8;TRUE;FALSE) ---> works
I noticed that the IF function requires a "logical test", while a SUMIF function requires a "criteria", but what is the difference between a criteria and the logical expression theoretically, how can I explain why this is necessary to use? (other than "just because excel works this way...)
The majority of the question appears answered by a comment from #Jeeped
Excel is looking for specific information for each of these parameters. First, I would recommend you familiarize yourself with Excels operators a little bit.
=IF(logical_test, [value_if_true], [value_if_false])
In this, we are looking for a Boolean expression from the logical test. Something to resolve to either true or false, with possible actions for either scenario. So comparison operators would fit naturally in there.
=SUMIF(range, criteria, [sum_range])
In this function excel is doing a direct comparison of the criteria to values existing in the range. If the criteria is true, then add to the sum array and move to the next. Once all true statements are found, sum them all and provide the result. So a comparison within the criteria doesn't work as the function is already doing a comparison of the criteria to the range.
The difference here, is the logical test in the IF statement must resolve to true or false and it is not expecting a string. The criteria in the SUMIF statement must exist as a value within the range to be summed. So the criteria must resolve to a value that exists within a range. This is done by interpreting the SUMIF criteria as a string to compare it to a ranges value string.
Why then is the quote and ampersand needed?
It boils down "just because excel works this way..."
Or, more specifically, quotes and ampersands are part of the basic syntax and operations of excel itself.
Or, in a totally non-technical sense:
Excel operators are like problem children. They always need both hands held. Always something on the left and right. They don't like leaving a hand free.
I have some data that are in tables, i need to find a match in multiple array locations. If i'm looking for only one location i'm good, but if i need to find it in another location lets say, location!A6:J6 i get #value. Here my lookup.
=INDEX(location!A8:J8,MATCH(W_D!A6,location!A10:J10,0)) 'this is cell B6 formula *works fine
=INDEX(location!A6:J6&location!A8:J8,MATCH(W_D!A6,location!A4:J4&location!A10:J10,0)) 'Here is the issue.
*Note: one of my table is upside down as well.
You can use a concatenated or a nested formula. There are many ways to compose it but may be the easiest would be to combine many INDEX/MATCH combinations so that the result would be the one that matches the entry.
I will first describe the general method and then apply it to your case. You have a search formula that works correctly in one range, but you want to apply many searches in many ranges. There are two methods to achieve this in general:
Method 1: Concatenation
=IFERROR(search1, "") & IFERROR(search2, "") & IFERROR(search3, "")
Only the successful search will appear as a result of this concatenation. If non succeeds, result is blank. However, if many succeed, result will be their concatenation.
Method 2: Nesting
We can also nest the IFERROR statements. In general this is more complex to edit but it solves the problem of duplicate results.
=IFERROR(search1, IFERROR(search2, IFERROR(search3, "Not Found")))
I prefer Method 1 in your case since you know that your search wont have duplicate results.So we keep it simple and apply the concatenation method to your case:
=IFERROR(INDEX(location!A6:J6,MATCH(W_D!A6,location!A4:J4,0)), "") &
IFERROR(INDEX(location!A8:J8,MATCH(W_D!A6,location!A10:J10,0)), "")
With Method 2 the formula is:
=IFERROR(INDEX(location!A6:J6,MATCH(W_D!A6,location!A4:J4,0)), IFERROR(INDEX(location!A8:J8,MATCH(W_D!A6,location!A10:J10,0)), "Not Found")
I'm currently using this expression to check if a cell contains at least one of a set of strings:
A B
1 abcd =ISNUMBER(SEARCH({"a","x"},A1))
B1 will return true here. However if I change the order of the array as follows it returns false:
A B
1 abcd =ISNUMBER(SEARCH({"x","a"},A1))
Why is that? Is there a better way to do this that's more elegant than using a bunch of OR()'s?
Say we have text in A1 and we also have a list of sub-strings in column C. These can be either single or multiple character substrings. We assign the Name - KeyStrings to the list of cells in column C
We want to know if any of the substrings is present in A1.
Enter the following in B1:
=NOT(LEN(TRIM(SUBSTITUTE(A1,INDEX(KeyStrings,SUMPRODUCT(ROW(KeyStrings)*ISNUMBER(SEARCH(KeyStrings,A1)))),"")))=LEN(A1))
The formula will report True if any of the substrings in column C can be found in A1
Just for completeness, the answer to the original question "Why is that?" i.e. why does the result seem to be sensitive to the order of the strings in curly brackets is that the formula
=ISNUMBER(SEARCH({"a","x"},A1))
only looks at at the first string "a" because there is nothing to make it operate like an array formula and step through all the values "a","x" etc.
The usual procedure is to wrap the function in an aggregate function like SUM. If you do this you also have to add minus signs to make the TRUE/FALSE values from ISNUMBER behave as ones and zeroes and further wrap in SUMPRODUCT or enter it as an array formula to make it work:-
=SUMPRODUCT(SUM(--ISNUMBER(SEARCH({"a","x"},A1))))
Even then it gives a numeric result which is not what you actually want.
# Dirk Reichel's idea is therefore much better giving you:-
=OR(ISNUMBER(SEARCH({"a","x"},A1)))
which works very nicely and incidentally doesn't need to be entered as an array formula.
I think since you have put a curly bracket there, it indicates an array search. (I am not an expert with arrays, so following is an educated guess).
What Excel is doing is in the first example, it is finding "a" in position no 1, so it is returning the no 1 to ISNUMBER function, which is TRUE. (Basically, compares "a" to a in abcd which is position 1, and doesn't find/look for[?] "x". Returns 1 for the "a", which is TRUE for ISNUMBER function)
In the 2nd code, "x" is compared to a from abcd, which returns a non-numeric value (and doesn't find/look for[?] "a"), hence it is FALSE.
PS:
what I mean by Excel doesn't find/look for[?] the second or any element there on, seems to be based on how arrays and formulae are coded in. In the curly brackets, commas separate "columns" and semi-colons separate "rows". So you are entering a 2 column/1row array inside a search function. While there is nothing wrong with that, the SEARCH function itself may not be coded to look for any element in the array apart from the one in position [1,1]. Someone better informed with the inner workings of SEARCH function should confirm this answer. (If it is a completely wrong educated guess, I wouldn't mind taking it off)