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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Krish2459_58
Creator II
Creator II

adding leading zeros

Hi,

 

I need to add leading zeros

  • If last character in a string having one integer  then add three leading zeros.
  • If last character in a string having two integers then add two leading zeros.

ex:

ACCL25 = 00ACCL25

ACCL9 = 000ACCL9

 

Thanks..

 

 

Labels (1)
2 Solutions

Accepted Solutions
rubenmarin

Hi:

If(IsNum(Right(FieldName,2))
  ,'00'& FieldName
  ,If(IsNum(Right(FieldName,1))
    ,'000'& FieldName)) as FieldName2

View solution in original post

MayilVahanan

Hi

Try like below


Load *, Repeat(0, 8-Len(field1))&field1 as field2 Inline
[
field1
ACCL25
ACCL9
];

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

4 Replies
rubenmarin

Hi:

If(IsNum(Right(FieldName,2))
  ,'00'& FieldName
  ,If(IsNum(Right(FieldName,1))
    ,'000'& FieldName)) as FieldName2
MayilVahanan

Hi

Try like below


Load *, Repeat(0, 8-Len(field1))&field1 as field2 Inline
[
field1
ACCL25
ACCL9
];

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
BrunPierre
Partner - Master II
Partner - Master II

Hi, try the below.

Text(If(Len(KeepChar(FieldName,'0123456789')) =1, '000'&FieldName,
If(Len(KeepChar(FieldName,'0123456789')) =2, '00'&FieldName))) as FieldName2

JaWa
Contributor II
Contributor II

Absolutely brilliant! Thank you very much!