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

Strange Behavior Removing Leading Zeros

Hi all,

Recently I came across a strange behavior, and wanted to check forum whether there is a solution.

In QlikView Script, I want to load below 2 text records  and remove leading zeros.

MuratErcan1_0-1661593531003.png

However, whatever I try, I keep getting strange results. I am using the below script:

T1:
LOAD
    MAT,
    Text(MAT) AS MAT_TXT,
    Replace(Ltrim(Replace(Text(MAT), '0', ' ')), ' ', 0) AS MAT_NoZeros_1,
    Replace(Ltrim(Replace(MAT, '0', ' ')), ' ', 0) AS MAT_NoZeros_2
;
LOAD * INLINE[
    MAT
    0195-0012-10
    0195-0012-010
];

 

 

I am getting the below as the result.  "0" from the "010" is also dropped.

MuratErcan1_1-1661593888323.png

I know that Qlik engine stores "010" and "10" as one value when it is a numeric field, but in this case it is a text field and 010 is not even in the beginning.

I guess Somehow, "-" character is causing Qlik engine to store values as separate numeric values??

 

Even more strange is, the behavior changes when there is only one "-" character. when I load below 2 entries instead, result is as expected. "010" and "10" of these strings are interpreted correctly.

MuratErcan1_3-1661594348331.png    MuratErcan1_2-1661594303315.png

 

I have tried replacing "-" with "|", removing leading zeros and then replacing "|" back to "-".  Removing leading zeros worked with "|" character, but when replace them with "-", bam! leading zeros starts appearing again. 

T1:
LOAD
    MAT_NoZeros_3,
    Replace(MAT_NoZeros_3,'|','-') AS MAT_NoZeros_4
;
LOAD
    Replace(Ltrim(Replace(
        Replace(Text(MAT),'-','|')
    , '0', ' ')), ' ', 0) AS MAT_NoZeros_3
;
LOAD * INLINE[
MAT
    0195-0012-010
    0195-0012-10
];

 

MuratErcan1_4-1661595378277.png

 

Any thoughts on how to handle this? Any help is much appreciated!

 

Thanks,

Murat

 

Labels (1)
1 Solution

Accepted Solutions
BrunPierre
Partner - Master
Partner - Master

Just wrap the expression around with Text() to ensure it is treated as such.

Text( Replace(Ltrim(Replace(Text(MAT), '0', ' ')), ' ', 0) ) AS MAT_NoZeros_1

View solution in original post

1 Reply
BrunPierre
Partner - Master
Partner - Master

Just wrap the expression around with Text() to ensure it is treated as such.

Text( Replace(Ltrim(Replace(Text(MAT), '0', ' ')), ' ', 0) ) AS MAT_NoZeros_1