Need to understand fomula re: excel search for a string in a table and return string if true - excel

I've adapted this solution from a couple of years ago:
=LOOKUP(2^15,FIND(Keywords,A2),Categories)
I use this for searching within a description field for keywords in a named list, in order to return a corresponding category from an adjacent named list.
However I do not understand the significance of 2^15. Can someone explain?
Also it's unclear in what order the search operates. If two keyword options were "check" and "deposit," and they were assigned to different categories, but both appeared in the same description field cell, how do I know which will be found first? Is it placement in the string, or order in the list?

2^15 is simply an arbitrarily large number, which lookup attempts to find - when it can't find it, it takes the next lowest number.
Effectively your formula looks at Keywords, and attempts to find the value in A2. For each word that actually matches A2, it provides a non-error message. Then out of the whole list, it attempts to find that line number in categories, resulting in many errors, and a single correct value. Lookup picks the value by using 2^15. Though this seems to be a weird way of doing it; it is likely a holdover of pre-2007, as Lookup is generally used now only for backwards compatibility purposes. Also using 1 instead of 2^15 worked for a couple of simple cases that I tried when writing this up.

Related

FIND() formula to include "implicit intersection operator" change required

Over the weekend, my work laptop did a restart and Microsoft gave me the perfect gift in Excel, it introduced the implicit intersection operator which has completely messed up my world, literally every formula has gone crazy.
I've checked every link I can and cannot work out how to correct even the most basic formula. I would like to ask about this one so I can at least make some progress forwards.
=FIND('Value Definitions'!C3,'User Interface'!K:K) was my formula that was worked forever.
The explanation of this formula is to flag all value definitions that have been used within text of all rows in the user interface column K.
When Excel asks me to correct the formula, it rewrites it as =FIND('Value Definitions'!C3,#'User Interface'!K:K).
This results in #VALUE rather than a number of where the first occurrence was found. If I remove the # then I get #SPILL!.
Just to reiterate the purpose of the formula, I identify which phrases exist in an interface that come from the value definitions worksheet, irrespective of the number value I get (character count of first occurence), I just want to identify that it exists at least once. Then I can use this flag to lookup all related value definitions to be included on the user interface.
Thanks for your help in advance.

Counting number of occurences of a specific search string

I'm building a monitoring system that takes a log (where people register their work in a set format) and returns a counter, which I can use for analysis. The monitor and log are two separate workbooks. The log has entries like this: INITALS;DATE;HOUR:RESULT|
Each cell can contain multiple entries.
My first attempt was to do a simple countif and look for a string (note that I use ; instead of , in formulas since I work on a Dutch excel):
=COUNTIF('LOCATION'!Table[LOG];"*NB;??/??/????;??:??:#A*|*")
This worked fine, but the formula only counted the number of cells where this string was present, not the actual number of occurences. I then tried this solution.
=SUM(LEN('LOCATION'!Tabel13[LOG])-LEN(SUBSTITUTE('LOCATION'!Tabel13[LOG];"NB";"")))
This indeed counted the number of times "NB" was present in the LOG. However, when I tried to use the original search string, this solution stopped working:
=SUM(LEN('LOCATION'!Tabel13[LOG])-LEN(SUBSTITUTE('LOCATION'!Tabel13[LOG];"*NB;??/??/????;??:??:#A*|*";"")))
It seems to me that SUM does not recognize symbols like ? or * which are necessary to define the correct search string. Where did I go wrong? Or can this be solved in another way? I can still look into VBA, but the workbooks are slow as hell already.
"?" and "*" are wildcards. Some functions support these (like COUNTIFS()) where others don't. Like you found out, SUBSTITUTE() does not.
Here is one way to count, assuming ms365:
Formula in C1:
=REDUCE(0,A1:A2,LAMBDA(a,b,a+LET(X,SEQUENCE(LEN(b)),SUM(--(IFERROR(SEARCH("NB;??/??/????;??:??:#A*|*",b,X),0)=X)))))
Note: I removed the asterisk in front of "NB" just to make searching for a position valid in comparison to what i called variable "X".

Excel VLOOKUP returns #N/A when allowing approximate match, but returns value when requiring exact match?

Run across a very strange issue that I am curious about. In Excel, I was doing a VLOOKUP to match contact names with a unique ID found in another database. Formula for example: =VLOOKUP(B2,Sheet2!A:B,2,TRUE), very basic. I used approx. match but, of course, some instances still returned #N/A. However, I did double checks with a quick control-F and found a number of instances returning NA when there was in fact a (exact) match. I was troubleshooting and trying a number of things but nothing was working. Many checks confirmed the cells were equal, there was nothing tricky like hidden characters, very peculiar. Anyway, on a whim I changed from approximate match to exact match and lo and behold it worked! The VLOOKUP was returning the correct value.
I'm trying to understand why this is. Obviously if you were requiring an exact match but there was only an approx. match it would return NA. But it doesn't make sense the other way around. An exact match should be returned when allowing even approx. matches! So just trying to understand what is going on behind the scene in VLOOKUP/Excel to make this phenomenon occur.
Appreciate any insight!
When working with approximate VLOOKUP, the key-column (always the 1st column of matrix-range) in the lookup-matrix should always be sorted in ascending order. The reasons for this is the following:
Imagine a key column with the values [2,3,10,4] in the given order. When the key '4' should be looked-up approximately, the function will start comparing the available keys in the column, beginning with '2'. After '3' was passed, '10' follows, which is already greater than the searched '4'. Consequently, the function stops searching and returns the target value of the previous key-row ('3') as an "approximation".
Now, given another example [10,2,3,4]. Here, approx. VLOOKUP will stop searching right after the first key comparison as '10' is greater than the searched '4'. Since no previous key-row is available, the returned value will be #N/A. However, an exact VLOOKUP would have found the matching key as it does not stop searching.
Besides key order, it is recommended to have all the key-values in the same format.
Hope this helps.

SumProduct Using Multiple Criteria Returning Too Much Data

Although this question has been asked and answered, (Stack Overflow is where I learned how to implement SP), an issue has come up which I can't figure out.
I'm using SP to sum shipments within a pivot table using a product number (with wild-cards), and a specific date. For instance, part numbers can be "AX10235-HP", "AX11135-HP", "AX10235-HP2", "AX10235-HPSPARE" or TP10101-IBM. (There are a large variety of numbers.)
So in this case I want to sum the qty shipments of "AX???35-HP". I wish to sum just the first 2 parts in my short list. However, the command used causes all the parts to sum except the *-IBM number; as if there was a wild-card at the end of the number. In other words "AX???35-HP" is the same as "AX???35-HP*". I've tried wrapping the value in quotes but it takes uses the quotes literally so fails.
This is the function
SUMPRODUCT((S_PART_DATA)*(ISNUMBER(SEARCH($A6,S_PART_RANGE))*(S_PART_DATES=T$4)))
S_PART_DATA array of Shipments,
S_PART_RANGE array of list of part numbers,
S_PART_DATES array of Dates shipments were made
It works the way you describe because SEARCH function finds $A6 within other text, hence it may not be an exact match - better to use SUMIFS function like this:
=SUMIFS(S_PART_DATA,S_PART_RANGE,$A6,S_PART_DATES,T$4)
Assuming all named ranges are the same size and A6 contains the value AX???35-HP
If that doesn't work try this version
=SUMPRODUCT(S_PART_DATA*ISNUMBER(SEARCH("^"&$A6&"^","^"&S_PART_RANGE&"^"))*(S_PART_DATES=T$4))
concatenating the ^ values means you will [probably] only get exact matches

Excel 2013, how to us the "search" function like vlookup

Essentially, I am looking for a way to use the "search" function like the "vlookup" function. In my case, I am have a long list, of say, 1000 descriptions of different types of fasteners and I want to classify them according to what they are, (ie. Nut, bolt, washer etc.). However, I can't sort by description or partnumber because they, alphanumerically, don't line up by class. But he descripotion field does say at some point in it, what it is(ie. Nut, bolt, washer etc.).
As said, I have a table of classes, and I am looking for a formula that would look in the "description" field for all the values in the table,and then return that value, or one associated with it (like vlookup does with cell values).
So that, if it found "nut" in the description, it would return "nut", or if it found "bolt" it would return "bolt."
I hope that this question makes sense. Let me also say that I found a way "manually" do this using the search function, along with others, but the formula was very long and each value in my table had to be specially called out. However, I will include the formula I used to make clear what I was trying to do.
See below.
=IF(ISNUMBER(SEARCH($G$2,C3)),$G$2,IF(ISNUMBER(SEARCH($G$3,C3)),$G$3,IF(ISNUMBER(SEARCH($G$4,C3)),$G$4,IF(ISNUMBER(SEARCH($G$5,C3)),$G$5,...IF(ISNUMBER(SEARCH($G$13,C3)),$G$13,"MISC"))))))))))))
You see that with each item you add to your table, you have to add another if loop. I am hoping there is a better way. (I would call it "vsearch" :-) )
Try this formula
=IFERROR(LOOKUP(2^15,SEARCH($G$3:$G$13,C3),$G$3:$G$13),"MISC")
SEARCH returns an array of numbers or errors depending on whether each term is found in C3. By searching for "bignum" (in this case 2^15) which won't be found, the match is always with the last number, i.e. the last matching term in G3:G13.
MATCH can be used to find the text, and INDEX can be used to return the text
using your example, where you are searching in G:
=MATCH("*"&C3&"*",$G:$G,0)
and then index to return the text
=INDEX($G:$G,MATCH("*"&C3&"*",$G:$G,0))
and as a finishing touch, the #VALUE! replacement
=IFERROR(INDEX($G:$G,MATCH("*"&C3&"*",$G:$G,0)),"MISC")

Resources