Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
wlpike
Contributor III
Contributor III

leading zero using Len()

Hi, 

i have an issue when importing data using ZIP codes from all over the world.

in the import script is want to identify the length of the zip codes using len(). 

It's working for almost every ZIP, but not for those that have leading zeroes. As it seems Len() is not recognizing a number (or a converted string) that begins with a zero.

the code i use is very easy:

Len(PLZ) 

 

i tried that too:

Len(Text(PLZ))

 

e.g. when checking ZIP codes "01007" i get "4" in return (in both cases)

 

But what startled me is that when using the same code in the analysis area i get the correct length (5).

 

So why does it not work in the script area?

 

thanks

br

chris

1 Solution

Accepted Solutions
Vegar
MVP
MVP

What you are telling us sounds like a big in my ears, Len() is a string function and I world expect it to return 5 in both your cases.

Im on vacation without access to try this myself, but if someone else are able to reproduce your error on the newest release of Qlik Sense then I suggest that you get in touch with Qlik Support in order to get it verified /registered as a bug.

A workaround could be something like this : Len('x' & text(PLZ) )  - 1 as Length

View solution in original post

5 Replies
Vegar
MVP
MVP

What you are telling us sounds like a big in my ears, Len() is a string function and I world expect it to return 5 in both your cases.

Im on vacation without access to try this myself, but if someone else are able to reproduce your error on the newest release of Qlik Sense then I suggest that you get in touch with Qlik Support in order to get it verified /registered as a bug.

A workaround could be something like this : Len('x' & text(PLZ) )  - 1 as Length

Saravanan_Desingh

Nice thought @Vegar . It's working.

wlpike
Contributor III
Contributor III
Author

Hi @Vegar 

thanks for this solution. On the first view its working, but it seems there is again a difference between using the code in load script or in analysis area.

 

Now for most of the zip codes i get the correct lenght, but for some of them not.

What puzzles me is that i get a different length for the same zip code. E.g.  '0002'

sometimes i get "1" sometimes  i get "4"

When i use your code in a chart table i alway get length "4".

 

do you know why this could happen?

 

 

arulsettu
Master III
Master III

Can you share sample data to reproduce the issue

wlpike
Contributor III
Contributor III
Author

okay i think i have got it.

 

@Vegar your solution is absolutely correct. i get correct length for the zip code that (like descibed above) is actually "2" and not "0002". So what i find curious is that qlik shows me "0002" as zip code although in source file i have "2" 

 

Raw data looks like this:

order_number;ticket;name;surname;E-Mail;country;state;address;zip_code

"2019-08-20 08:35:36";"mobile";"Jon";"Doe";"jd@yahoo.com";"IE";"Dublin";"Jon Doe Way";"2"

"2019-11-09 12:04:26";"mobile";"Artur";"Conan";"ac@gmail.com";"UK";"London";"buckingham palace";"0002"

 

so whats wrong is that my qlik table in analysis mode shows a totally wrong zip code ("0002" in both cases) and therefore length function used in analysis mode is wrong too...