In my table I have a text column, and I need to check if the 5 characters of the string is specifically an exclamation point followed by 4 (dynamic) numbers - '!XXXX' - example !0422, the 4 numbers are not known, just need to know it there's a ! followed by 4 numbers.
Is there an M function to handle that without creating a 9,999 if statement?
add column, custom column, with formula as below, replacing [Column1] with the name of your text column
= try if Text.Start([Column1],1)="!" and Number.From(Text.End([Column1],4))>=0 then "YES" else "NO" otherwise "NO"
if you are not sure it will always be 5 characters, you could also check length:
= try if Text.Start([Column1],1)="!" and Text.Length([Column1])=5 and Number.From(Text.End([Column1],4))>=0 then "YES" else "NO" otherwise "NO"
Related
I'd need to split or extract only numbers made of 8 digits from a string in Google Sheets.
I've tried with SPLIT or REGEXREPLACE but I can't find a way to get only the numbers of that length, I only get all the numbers in the string!
For example I'm using
=SPLIT(lower(N2),"qwertyuiopasdfghjklzxcvbnm`-=[]\;' ,./!:##$%^&*()")
but I get all the numbers while I only need 8 digits numbers.
This may be a test value:
00150412632BBHBBLD 12458 32354 1312548896 ACT inv 62345471
I only need to extract "62345471" and nothing else!
Could you please help me out?
Many thanks!
Please use the following formula for a single cell.
Drag it down for more cells.
=INDEX(TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(SPLIT(REGEXREPLACE(A2&" ","\D+"," ")," "))=8,
SPLIT(REGEXREPLACE(A2&" ","\D+"," ")," "),"")),"where Col1 is not null ",0)))
Functions used:
QUERY
INDEX
TRANSPOSE
IF
LEN
SPLIT
REGEXREPLACE
If you only need to do this for one cell (or you have your heart set on dragging the formula down into individual cells), use the following formula:
=REGEXEXTRACT(" "&N2&" ","\s(\d{8})\s")
However, I suspect you want to process the eight-digit number out of all cells running N2:N. If that is the case, clear whatever will be your results column (including any headers) and place the following in the top cell of that otherwise cleared results column:
=ArrayFormula({"Your Header"; IF(N2:N="",,IFERROR(REGEXEXTRACT(" "&N2:N&" ","\s(\d{8})\s")))})
Replace the header text Your Header with whatever you want your actual header text to be. The formula will show that header text and will return all results for all rows where N2:N is not null. Where no eight-digit number is found, null will be returned.
By prepending and appending a space to the N2:N raw strings before processing, spaces before and after string components can be used to determine where only eight digits exist together (as opposed to eight digits within a longer string of digits).
The only assumption here is that there are, in fact, spaces between string components. I did not assume that the eight-digit number will always be in a certain position (e.g., first, last) within the string.
Try this, take a look at Example sheet
=FILTER(TRANSPOSE(SPLIT(B2," ")),LEN(TRANSPOSE(SPLIT(B2," ")))=8)
Or this to get them all.
=JOIN(" ,",FILTER(TRANSPOSE(SPLIT(B2," ")),LEN(TRANSPOSE(SPLIT(B2," ")))=8))
Explanation
SPLIT with the dilimiter set to " " space TRANSPOSE and FILTER TRANSPOSE(SPLIT(B2," ") with the condition1 set to LEN(TRANSPOSE(SPLIT(B2," "))) is = 8
JOIN the outputed column whith " ," to gat all occurrences of number with a length of 8
Note: to get the numbers with the length of N just replace 8 in the FILTER function with a cell refrence.
Using this on a cell worked just fine for me:
(cell_with_data)=REGEXEXTRACT(A1,"[0-9]{8}$")
i have been thinking about this a lot.
So i wanna create a table which contains a password.
The password should at least be 6 chars long a contain minimum 2 numbers.
My version was:
create table User (
passwort varchar(80) not null check (length(passwort) >= 6 and passwort like '%[0-9]%[0-9]%')
);
The Problem with this approach is that the password has to contain [0-9] twice instead of the actual numbers. Does anyone know how to get rid of that problem ?
Thanks in advance.
How about .*?\d.*?\d.*?
This ensures that between zero or more characters (including digits), there must be 2 digits.
While I still recommend you split the work in 2 as per my comment, ie.
Check the length of the string.
Use the actual expression to check if the string contains 2 numbers.
You can use the following expression: ^(?=.{6,}).*?\d.*?\d.*?$. What is does is that it looks ahead for a minimum of 6 characters and then checks that the string is made up from 2 numbers, which can be separated by 0 or more characters.
An example of the expression is available here.
I have a text column in PowerBI, with numeric digits separated by a hyphen. I need the left side to be exactly 5 digits. If it is less, then add leading zeros. The right side needs to be 4 digits. Any less, add leading zeros.
For example:
0002-800 -> 00002-0800
0001-0800 -> 00001-0800
12345-220 -> 12345-0220
Any help is appreciated.
Thanks
Edit the query. Let's assume the text is in a column called "code".
Split the column by delimiter, using the dash as the delimiter
Create a new column that pads the code.1 with 0 if its length is less than 5, else use code.1
Create a new column that pads the code.2 with 0 if its length is less than 4, else use code.2
append the two helper columns with a dash in between
remove the code and helper columns and rename the remaining column to your liking.
Text.Length will return the length of a string, Text.PadStart() will pad text. The formula for step 3 above is
if Text.Length([code.1]) < 5 then
Text.PadStart([code.1], 5, "0")
else
[code.1])
You can do this with one step:
= Table.TransformColumns(
Source, {"Column", each Text.Combine({
Text.PadStart(Text.BeforeDelimiter(_, "-"),5,"0"),
Text.PadStart(Text.AfterDelimiter(_, "-"),4,"0")
},"-"
),type text}
)
0
votes
1 view
Hi,
I have a scenario, where in we have a single record and multiple columns like this
Record_number cd1 cd2 cd3 cd4 cd5 cd6 cd7 cd8 cd9
Here are values for the for the above record
123 12 null 13 14 null 15 16 17 null
Here we have value for cd1 and not for cd2 and we have value for cd3 so cd2 is empty so cd3 should get into cd2 since it was empty so we should move the next available values to previous available spaces.
Does anyone know how to achieve this scenario?
If I understand your question correctly, this can be easily done using an expression transformation.
First create a variable port that would concatenate all the non-null values using some separator, e.g.|, like:
IIF(ISNULL(cd1),'',cd1 || '|') ||
IIF(ISNULL(cd2),'',cd2 || '|') ||
...
IIF(ISNULL(cd9),'',cd9 || '|') ||
This should result in pipe delimited list with the nulls removed, e.g.:
123|12|13|14|15|16|17|
Next create an output port for each column, that would get the correct substring using index of the separator. I'll leave coding this part to you, but if you'd have issues, please let me know.
One approach could be to use an expression transformation as follows:
First concatenate all the ports in a single field using a delimiter (for example ',')
v_CONCAT:= cd1||','||cd2||','||cd3||','||cd4||','||cd5||','||cd6||','||cd7||','||cd8||','||cd9
Now create the output ports using regular expressions
o_cd1:=REG_EXTRACT(v_CONCAT,',*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*)',1)
o_cd2:=REG_EXTRACT(v_CONCAT,',*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*)',2)
o_cd3:=REG_EXTRACT(v_CONCAT,',*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*),*([^,]*)',3)
.
.
and so on.
REG_EXTRACT extracts a substring from the input string that matches the regular expression.
() - a group. There will be as many groups as your ports cd1-cd12
,* - zero or more commas, if a value is null two commas will appear consecutively
[^,] - anything other than comma
[^,]* - zero or more of any character other than comma
The third parameter to REG_EXTRACT denotes which group you want as output. For o_cd1 we want the first non-NULL value, so it is 1 and for o_cd2, it is 2 and so on
I am trying to search a varchar2 column in a table for matching strings using the value in another column. The column being searched allows free form text and allows words and numbers of different lengths. I want to find a string that is not part of a larger string of text and numbers.
Example: 1234a should match "Invoice #1234a" but not "Invoice #1234a567"
Steps Taken:
I have tried Regexp_Like(table2.Searched_Field,table1.Invoice) but get many false hits when the invoice number has a number sequence that can be found in other invoice numbers.
Suggestions:
Match only at end:
REGEXP_LIKE(table2.Searched_Field, table1.Invoice || '$')
Match exactly:
table2.Searched_Field = 'Invoice #' || table1.Invoice
Match only at end with LIKE:
table2.Searched_Field LIKE '%' || table1.Invoice