Excel: INDEX MATCH with partial number - excel

I have a large table of 12 digit numbers and associated info
I have a small list of 10 and 11 digit numbers (the first and/or last digits were cut off) - I'm attempting to cross these two lists to identify the items on the small list
normally, I'd use an index match to bring the associated info out of the table into the list, but because today I have only partial numbers in my list, I can't get the formula to work
I've seen other examples here that search for partial text strings contained within a range, but I haven't been able to adapt those formulas to my data. wildcards don't seem to work with numbers.
Many thanks for your input, and apologies in advance if I failed to find an existing solution on the site.

To match partial numbers inside a number range, like you do with strings, you can use an array formula with INDEX/MATCH, by composing a temporary array that converts the numbers into strings.
Say column A is your 12 digit numbers column, and you want to match the sequence 1234567890 and retrieve the value from column B, This CSE formula works:
=INDEX($B$2:$B$9999, MATCH("*1234567890*",""&$A$2:$A$9999,0))
CtrlShiftEnter
Although you can use full columns A:A and B:B, this should be avoided as much as possible with array formulas, because they're slow. Full columns mean computing and operating arrays of more than a million entries, so avoid it. Also note the "expensive" conversion from numbers to strings (all numbers in the $A$2:$A$9999 are converted to strings here).
To use a cell reference, say D2, instead of the harcoded 1234567890, the formula should be used like this:
=INDEX($B$2:$B$9999,MATCH("*"&D2&"*",""&$A$2:$A$9999,0))

Related

Excel - Add an excel formula within FilterXML

I have an excel spreadsheet containing a list of strings in one column. The list of strings is made up of several numbers from varying lengths, separated by “/” and “;” The first entry of the string is a code id (which always has a length of 3)(red in example) followed by an “/” then an amount (which varies in length)(green in example) followed by an “;” if the string continues.
With the help of a member, I can now isolate the green number with the following formula:
=IF(ISBLANK(A4);"";TRANSPOSE(FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(A4;"/";";");";";"</s><s>")&"</s></t>";"//s[position() mod 2 = 0]")))
However, I still need an other formula that multiplies the green number with a variable, if a condintion is met.
Example function:
=IFS(B2<=10;B2*1,25;B2<=20;B2*1,18;B2<=100;B2*1,05;B2<=250;B2*1,01;B2>250;B2)
Is there a way to combine both these functions?
A very nice way of dealing with this is assigning the full array to a name, let's say a variable, through LET(). So your formula in B2 would become:
=IF(A2<>"",LET(MNT,TRANSPOSE(FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(A2,"/",";"),";","</s><s>")&"</s></t>","//s[position() mod 2 = 0]")),IFS(MNT<=10,MNT*1.25,MNT<=20,MNT*1.18,MNT<=100,MNT*1.05,MNT<=250,MNT*1.01,MNT>250,MNT)),"")
It, however, does require Excel O365. But since you are transposing the array it appears you do have that.

Check for one, two or three digits in a VLOOKUP

I have around 30 numbers which are either 1, 2 or 3 digits which are codes. These codes are attached in front of other numbers. I want to know what code is in front of a number, for example for the number 35467036 the first two digits matches with the code 35. So I want the output for that to be 1.5.
This is my current setup, I have a table with all the codes followed by the output in the next column. If all the codes were three digits long I could just do this =VLOOKUP((LEFT(E6,3)&"*"),D1:E3,2,FALSE) but they are unfortunately not.
I have also tried using nested IF statements but I can only go so far as 7 levels.
Will this only be possible in VBS or is there anther way?
Edit:
The code column is formatted to text. If I enter the value 3 into LEFT it does not work for two digits. Is there anyway I can make it work for 1, 2 and 3 digit codes? Also the codes do not overlap, for example, there isn't going to be 96 and 965 in the code table.
Seven nested IFs as a limit points to a very old version of Excel. You may want to consider upgrading to a version that is still supported in this millennium.
But your main problem is that the data type of your lookup value is text, because you concatenate a string with a wildcard. Whereas your Lookup Table's first column is probably made up of numbers.
In order to solve this you will need to add a Text column to your lookup table that represents the numeric value as a text value.
IF you want to use Vlookup, that helper column will need to be the first column of your lookup range.
You can use an Index/Match instead of Vlookup to be independent of the column order, as this screenshot shows:
Column H shows the formula that has been applied in column G.
Edit:
According to the screenshot you posted, you want to look up from the table in columns E to F and this table only has the short codes. Therefore, it makes no sense to add a wildcard to the lookup value. You just need to extract the value you want to use for the lookup.
If you want to lookup only two digits, then you need to extract only two digits. Adding a wildcard does nothing to remove the third digit.
In the screenshot below, a helper column feeds the LEFT() function the number of characters to extract, then uses that value in the VLookup.
=VLOOKUP(LEFT(A1,B1),$E$1:$F$5,2,FALSE)
=INDEX($G$2:$G$5,
SMALL(
IF(LEFT(A1,3)*1=$F$2:$F$5,ROW($G$2:$G$5)-1,
IF(LEFT(A1,2)*1=$F$2:$F$5,ROW($G$2:$G$5)-1,
IF(LEFT(A1,1)*1=$F$2:$F$5,ROW($G$2:$G$5)-1))),1))
=INDEX(LookupValues,Small(ArrayOfRowsFromIfStatements,FirstRow))
This is an array formula so you will need to use Ctrl+Shift+Enter while still in the formula bar.
We use If to build an array of Row numbers where the conditions match or return FALSE if not. The Small function then returns the smallest result in the array which will be the first row where conditions match.
We then index the results returning that row number (-1 deducted from rows to offset the headers).
If your numbers in column A are always 6 digits + the code length you can use this:
=VLOOKUP(--LEFT(A1,LEN(A1)-6),E2:F5,2,FALSE)

Count values after specific pattern in column occurs

My problem explained in Excel
Column A1:A22 have some binary numbers (0, 1). As you can see I highlighted numbers with GREEN fill color that match my pattern I want to find.
Column C5:C22 have formula as you can see in formula box, that CONCATENATE first four numbers ( A1:A4, A2:A5 etc..) in data set and check if it matches my pattern.
If this first four numbers match my pattern, I want Excel to count all NEXT numbers that are right after this pattern.
The biggest problem is that I can't do this this way because I have data set that have approximately 30.000 binary records in it, and my RAM memory can't handle that much of CONCANTENATE formula to count all NEXT values, after my pattern occurs.
I want someone to help me find other way without making HELPER columns, I want Excel formula, that in steps:
Search for pattern in data set..
IF pattern in data set matches my desired pattern, make AVERAGE of all values right after pattern occurs. So in example above my AVERAGE in cells C5:C22 = 0,66
I hope that I explain this in details so you know my problem, I need formula to do all the math stuff, I can't use helper columns like in example above.
Thanks in advance.
Concatenate once then Substitute Pattern to find
You can use CONCATENATE function in one cell, getting all the 1's and 0's into one cell.
Then SUBSTITUTE the Pattern to find with empty string "".
Then count how many Patterns were "Substitued" (Matched).
Like so:
Formulas in cells
D5-Concat all: =CONCAT(A1:A22)
E5-Len all: =LEN(D5)
F5-Substitute: =SUBSTITUTE(D5;Pattern;"")
G5-Len after: =LEN(F5)
H5-Matches: =(E5-G5)/PatternLen
To get it into one cell:
=(LEN(CONCAT(A1:A22))-LEN(SUBSTITUTE(CONCAT(A1:A22);Pattern;"")))/PatternLen

Find Duplicates in a column with large number (as text)

I have a SpreadSheet with a column with large number represented as text, and when I apply the duplicate operation to check ( I do not use any formula, I am using excel 2010 in-built functionality of "Conditional Formatting" -->"Highlight Cells Rule" --> "Duplicate Values") even distinct values are shown as duplicate values.
For example:
If I just have following values in a column of spread sheet:
26200008004000800000000000000001
26200008004000800000000000000002
26200008004000800000000000000003
It shows as all 3 values being duplicate.
How do I fix this and check for duplicates with these large numbers in excel.
P.S: I know excel has a 15 digit limit to precision, but is there a work around or another application to find duplicates.
It seems that DupUnique property is converting the value to a number. I also note similar behavior with COUNTIF. Accordingly, I would suggest, in this situation, that you use the conditional format option to use a formula. The formula I would suggest (assuming that the range to check for duplicates is A2:A10, would be:
=SUMPRODUCT(--($A2=$A$2:$A$10))>1
I use a helper column in which I concatenate the number with a letter to make it an alphanumeric entry.
=concatenate("a",'large number cell')
or
="a"&'large number cell'
a26200008004000800000000000000001
I hope this works for you.
When pasting the numbers into Excel, put an apostrophe in front of the number to convert the number to text like this
'26200008004000800000000000000001
Thereafter you can do duplicate checks using Data -> Remove Duplicates.
If you already have that kind of data in Excel, it may appear in Exponential values and chances are that Excel chomped it up to 15 digits numeric precision. You may have to re-enter the large data with apostrophe in front of them.

How to count number of cells whose contents start with 0?

I need to count how many cells are in a column, but all the content of the cells are id numbers that start with 0. For example, a column of numbers say A1-A3 looks like:
0253980
0253980
0250137
The answer should be "3" but =COUNT(A1:A3) produces "0". This is because the id numbers commence 0. I do not want to convert the numbers because they will be part of other queries later where people need to copy and paste thousands of id numbers into a program which will not work if the 0 is removed.
Is is possible to do a count on these cells?
In Excel what look like numbers are text strings when they start 0 (in general, though numbers may be displayed as preceded with one or more zeros through formatting - all credit to #chris neilsen for reminding me of that!), since Excel automatically strips leading zeros from numeric values. =COUNT:
counts the number of cells that contain numbers, and counts numbers within the list of arguments. Use the COUNT function to get the number of entries in a number field that is in a range or array of numbers.
so is not suitable for text strings. However =COUNTA:
Counts the number of cells that are not empty and the values within the list of arguments. Use COUNTA to count the number of cells that contain data in a range or array.
Hence fortunately the solution is very simply to substitute one function for the other and :
=COUNTA(A1:A3)

Resources