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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Prudhviqliks
Contributor II
Contributor II

Removing Zero's in a number

Dear guys,

I have a sample number of 0000123456000.

So how can I get the number only 123456?

Please any tips from anyone.

Labels (4)
4 Solutions

Accepted Solutions
mikaelsc
Specialist
Specialist

purgechar(number,'0')

keepchar(number,'123456789')

...

View solution in original post

Prudhviqliks
Contributor II
Contributor II
Author

Thank you @mikaelsc for quick response and solution , great 👌

 

View solution in original post

ratnadeep
Contributor II
Contributor II

@Prudhviqliks I encountered similar situation, but the number had 0 in between other digits (example 000012304000 and i was asked to extract 5 digit 12304 )

below is my approach. I have attached the output i achieved

test:
load * inline [

testnum
00012304000
00224580000
0000456780
012005000
];


for j = 0 to NoOfRows('test')

let vtest = peek('testnum',$(j),'test');
let vLenTest = len(peek('testnum',$(j),'test'));

for i = 0 to $(vLenTest)


if (left('$(vtest)',$(i))>0) then

temp:
Load
mid($(vtest),$(i),5) as extract1
AutoGenerate 1;
let i = $(vLenTest);
end if;

next i;

next j;

for k =0 to NoOfRows('test')
Output:
Load
peek('testnum',$(k),'test') as testnum,
peek('extract1',$(k),'temp') as output1
AutoGenerate 1;
next k;

drop tables temp,test;

 

View solution in original post

rwunderlich
MVP
MVP

A clever solution I have seen in this forum for removing leading and trailing zeros while maintaining embedded zeros is:

Replace(Trim(Replace(testnum, '0', ' ')), ' ', '0')

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

View solution in original post

7 Replies
mikaelsc
Specialist
Specialist

purgechar(number,'0')

keepchar(number,'123456789')

...

Prudhviqliks
Contributor II
Contributor II
Author

Thank you @mikaelsc for quick response and solution , great 👌

 

ratnadeep
Contributor II
Contributor II

@Prudhviqliks I encountered similar situation, but the number had 0 in between other digits (example 000012304000 and i was asked to extract 5 digit 12304 )

below is my approach. I have attached the output i achieved

test:
load * inline [

testnum
00012304000
00224580000
0000456780
012005000
];


for j = 0 to NoOfRows('test')

let vtest = peek('testnum',$(j),'test');
let vLenTest = len(peek('testnum',$(j),'test'));

for i = 0 to $(vLenTest)


if (left('$(vtest)',$(i))>0) then

temp:
Load
mid($(vtest),$(i),5) as extract1
AutoGenerate 1;
let i = $(vLenTest);
end if;

next i;

next j;

for k =0 to NoOfRows('test')
Output:
Load
peek('testnum',$(k),'test') as testnum,
peek('extract1',$(k),'temp') as output1
AutoGenerate 1;
next k;

drop tables temp,test;

 

rwunderlich
MVP
MVP

A clever solution I have seen in this forum for removing leading and trailing zeros while maintaining embedded zeros is:

Replace(Trim(Replace(testnum, '0', ' ')), ' ', '0')

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

Prudhviqliks
Contributor II
Contributor II
Author

Great @ratnadeep , expecting your contribution on this community more in future, thank you.

Prudhviqliks
Contributor II
Contributor II
Author

Sure @rwunderlich , thank you for your solution 🤝.

ratnadeep
Contributor II
Contributor II

Great help @rwunderlich !!! thank you very much.