Alteryx separate the first integer of a number and put it in a new column - alteryx

I only have one column that has an 8-digit number. No dots, commas or any conjugation. Only integers.
I simply want to extract the first integer from the number and put it to a new column named "First integer". I want the rest of the integers, untouched, to either go to a new column as they are, or stay in the existing column but without the first integer
for example now I have: columnA: 23456789
I want First Integer:2 columnA: 3456789
I am pretty new to Alteryx so that might even be a ridiculous question to some :P
But any help is greatly appreciated :)

Suppose [i] is the relevant numeric field in your Alteryx workflow.
Then using a Formula tool, this expression will give the first digit:
[i]/POW(10,FLOOR(LOG10([i])))
And this will give the remaining digits:
MOD([i],POW(10,FLOOR(LOG10([i]))))
Explanation: working inside-out: Log10([i]) tells you how many powers of 10 you're working with, FLOOR just rounds that off, POW(10,...) multiplies it back out... so basically for an 8 digit number, this gives 10,000,000. Then you simply divide to get the first digit, or take the MOD (modulus) to get the remaining digits.
PS, your question mentions an 8-digit integer... if you are absolutely certain that your integers always have 8 digits (and the first digit is not a zero), then you can shortcut this: firstDigit=[i]/10000000 and remainingDigits=MOD([i],10000000).

Related

Removing first two digits in Excel if the character length is greater than certain number

I have cell phone numbers in Excel some with country code- 91 and some without country code. I need to remove the country code. We have 10 digit phone numbers so I need to remove the first two digits if the character length of the cell is greater than 10, i.e. if I have a number with country code like 917465785236 I need to remove the first two digits- 91 so that I only have 7465785236. I am trying the below piece but it doesn't check the IF condition and removes the first two digits from all the cells. Can someone tell me what's wrong I am doing here:
=IF((LEN(A1>10)),RIGHT(A1, LEN(A1)-2))
You probably need to put the parentheses differently for the Len function:
=IF((LEN(A1)>10),RIGHT(A1, LEN(A1)-2))
You're not using the parenthesis properly. Also since you strictly want to have 10 characters, you don't need to calculated the length in the RIGHT formula.. It needs to be like this:
=IF(LEN(A1)>10,RIGHT(A1, LEN(A1)-2),A1)
Now, that is the issue with your formula, but the solution to your question doesn't even need a IF statement, You can simply use:\
RIGHT(A1,10)
It will automatically get the 10 characters at the end and remove the rest.

How to select a few numbers from a given number

If I have entered a certain 4 digit number for example ,1234 how do I choose like the first 2 numbers or the last two numbers from the cell by that i mean suppose i want it to return 34 for the last two digits and I want it to return 12 for the first two digits. So anytime I change my 4 digit number it works the same way.
You may use the LEFT and RIGHT functions, e.g.
=LEFT("1234", 2)
=RIGHT("1234", 2)
If your 4-digit number is, in fact, a string you can parse the string as suggested by #Tim Biegeleisen. In my Excel 365, when I enter 1234 in a cell formatted as General I can use the same method.
=LEFT(A1, 2)
and
=Right(A1, 2)
However, this conversion of a number to text mustn't be presumed to work under all circumstances. Therefore you may prefer to convert the number to text explicitly in the formula.
=LEFT(TEXT(A1,"0000"), 2)
and
=Right(TEXT(A1,"0000"), 2)
This method has the added advantage of being able to handle numbers of less than 4 digits.
On the other hand, you can also extract first and last digits from a true number, without converting it to text.
=INT(A1/100)
and
=MOD(A1,100)
The main difference is that the results are also numbers (all partial strings are text). Therefore this would be the preferred method if you don't want to worry about strings, text, numbers, numerics and cell formats.

How to get rid off only certain zeros formula?

Ok so I had a nice formula until a problem came along. Basically I needed to get rid off a zeros in the middle of a 10 characters String/Range i.e AB00005879 to do that I have used formula SUBSTITUTE(NameRange,"0","") which gave me nice AB5879 solution. Sometimes the number at the end would only be 3 digit long AB00000975 so my formula would give me AB975 All great until I stumble a problem. Some of the strings came in a form of i.e. AB00004020 So my formula extracted every zero leaving me with AB42. Is there a way to extract only first four zeros in a middle an always keep the number at the and? so the last scenario would look like AB4020. Thanks in advance
SUBSTITUTE(NameRange,"0",""))
If you always have two characters at the start and then some zeros and then some numbers, all of which you want to keep, this should work
=LEFT(A1,2) & VALUE(RIGHT(A1,LEN(A1)-2))
EDIT #2
If your string always starts with two letters such as AB following by a random number of zeros and then a number string that you want to keep, try
=LEFT(A1,2)&RIGHT(A1,11-AGGREGATE(15,6,ROW($3:$10)/(--MID(A1,ROW($3:$10),1)>0),1))
Replace A1 with your actual case.

Extracting certain numbers from a cell containing numbers and special characters

I have cells that contain both numbers and special characters such as this:
[1:250:10]
The 'coordinates' shown above can be in the following format.
[(1-9):(1-499):(1-15)] in terms of what numbers can be within each part.
How do I extract these three numbers into three separate cells?
Assuming your data is in Cell A1 the to extract first number use following formula
=MID(A1,2,(FIND(":",A1,1)-2))
for second number use
=SUBSTITUTE(MID(SUBSTITUTE(":" & A1&REPT(" ",6),":",REPT(":",255)),2*255,255),":","")
finally for third number enter
=SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(A1,":",REPT(" ",LEN(A1))),LEN(A1))),"]","")
Just tossing out some other options.
First number since it only has a length of 1 digit and is on the left side, use the following:
=RIGHT(LEFT(A1,2))
second number will be found by locating the : in the string
=MID(A1,FIND(":",A1)+1,FIND(":",A1,FIND(":",A1)+1)-(FIND(":",A1)+1))
third number will be dealt with in the same way as the second but we will use the second : and the ] as the identifiers as to where to grab from and how much to pull.
=MID(A1,FIND(":",A1,FIND(":",A1)+1)+1,FIND("]",A1)-(FIND(":",A1,FIND(":",A1)+1)+1))
now all those number will actually come through as text. If you want to have them as numbers in the cells, send them through a math operation that will not change their value. Do something like +0, -0, or *1 at the end. Alternatively you could add -- at the start of each formula (yes that is double - incase you were wondering if it was a typo)

Concatenate Custom Function

On a daily basis I need to load data to one of our systems. However Excel deletes the previous zeros in front of the contractor IDs. So i have to add THREE zeros manually. I normally use the CONCATENATE function however now the IDs are coming differently so some IDs now only need to have TWO zeros added.
example:
ID
911111
I use concatenate to make it look like:
000911111
I came up with the IF formula that detects if the ID starts with a number NINE, to concatenate TWO zeros and if not, then to add THREE zeros.
example:
=IF(LEFT(A32,1)="9",CONCATENATE("00",A32),CONCATENATE("000",A32))
Now I want to create this formula as a custom defined so I do not have to write down the formula ever time I work on the data every day.
Any suggestions I will really appreciate.
In addition to the formatting responses provided in the comments, you could use the RIGHT function to cut off the leading zeroes to the appropriate amount.
For example, assuming A1 holds a string of numbers, between 0 & 9 digits long. We can create text representing a 9 digit string, with as many leading zeroes as necessary, as follows:
=RIGHT(REPT("0",9) & A1,9)
REPT("0",9) tells Excel to repeat the character "0" 9 times. It then tacks on whatever text is in A1. Then it takes only the rightmost 9 characters of the concatenation.
I generally would recommend the Formatting options noted in those comments, unless you need the text to be 9 characters for other formula purposes.

Resources