Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

eliminating zeros at the start of string

If I had a number with an indefinite amount of zeros proceeding it, how would I get rid of these zeros?

for instance, if this number was 000000000215454854, is there any way qlikview can eliminate these zeros at the start of the number?

I used this code, however it didnt seem to work. Thanks

if(LEFT(TRIM(@1),1)='0',RIGHT(@1,17),

if(LEFT(@1,2)='00',RIGHT(@1,16),

if(LEFT(@1,3)='000',RIGHT(@1,15),

if(LEFT(@1,4)='0000',RIGHT(@1,14),

if(LEFT(@1,5)='00000',RIGHT(@1,13),

if(LEFT(@1,6)='000000',RIGHT(@1,12),

if(LEFT(@1,7)='0000000',RIGHT(@1,11),

if(LEFT(@1,8)='00000000',RIGHT(@1,10),

if(LEFT(@1,9)='000000000',RIGHT(@1,9),

if(LEFT(@1,10)='0000000000',RIGHT(@1,8),

if(LEFT(@1,11)='00000000000',RIGHT(@1, 7),

if(LEFT(@1,12)='000000000000',RIGHT(@1,6),

if(LEFT(@1,13)='0000000000000',RIGHT(@1,5),

if(LEFT(@1,14)='00000000000000',RIGHT(@1,4),

if(LEFT(@1,15)='000000000000000',RIGHT(@1,3))))))))))))))))

15 Replies
Not applicable
Author

hi,

using trim function we can remove zeros.

num(ltrim(),field)

swuehl
MVP
MVP

I think you need to reverse your if()-functions in order to make it work for more than 1 zero.

But have you tried num#() / num() functions to parse them in as number and format as you like?

Maybe like

num(num#(FIELDWITHZEROS),'###.##') as NEWFIELD

?

Not applicable
Author

These are the functions ive used but to no avail.

num(ltrim(@1), @1) as product,

num(num#(@1),'###.##') as product,


QV is pulling in data in csv format and duplicating product codes. In my product code list box I have 2 sets of numbers.

For instance: 0000000215125424 and 215125424

I have no idea why this is happening as there doesnt appear to any proceeding zeros and the spreadsheet

swuehl
MVP
MVP

ltrim, rtim and trim functions only remove spaces.

Could you maybe post a small sample here?

Not applicable
Author

Thats what I though, although when I go to the csv file and apply the trim on that document, this fixes the solution.

This is a good short term fix, but I'd prefer QV to manipulate the code in future

swuehl
MVP
MVP

What do you mean with "when I go to the csv file"? You haven't used a QV function in script (like trim(@1) )? Have you used an excel function then?

Not applicable
Author

I used the trim function in both cases (in the QV doc and the csv file) and it only worked when I applied it to the csv. It did not work when I used the trim function in the QV document.

SunilChauhan
Champion II
Champion II

use the below code

mid(Fieldname,findoneof(Fieldname,'123456789'),len(Fieldname)-1)

Sunil Chauhan
Not applicable
Author

Hi,

plz find the attachment it may be helpful