Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
AquaCapriLyn
Contributor II
Contributor II

How to remove leading zeros without removing the zeros in the middle and end

Hello, I am trying to remove leading zeros from the left of a string. I have values that look like 'GH54673045', 000005674505, MFE6453-GW, 000000000532, and 00034002GER. Could you please help me resolve this issue? I tried using the num function but it returns Null values. I also tried the Replace function but it removed the zeros in the middle. For example, 000000004230043 would return 42343 instead of 4230043

Labels (1)
3 Replies
marcus_sommer

You may try something like:

if(isnum(myField), mid(myField, findoneof(myField, '123456789')), myField)

rubenmarin

Hi, if there are no spaces in the codes you can convert all zeros to spaces, use ltrim to remove the initial spaces and convert again spaces to zeros:

Replace(LTrim(Replace('FieldName','0', ' ')),' ', '0')

You can also convert first all spaces to a non-used character and then return it back, like:

Replace(Replace(LTrim(Replace(Replace('FieldName',' ','~'),'0', ' ')),' ', '0'),'~',' ')

If after the fisrt zero will be always a number you can use:

Mid('FieldName',FindOneOf('FieldName','123456789'))

Else you can use:

Mid('FieldName',FindOneOf(Upper('FieldName'),'123456789.-_ABCDEF...')) // complete with all possible characters except zero.

MarcoWedel

another way to start at the first character other than 0:

Mid(String,FindOneOf(String,PurgeChar(String,'0')))