Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

sudeepkm
Valued Contributor III

Generating blank spaces based on field value length

Hi,

I've a table like below

sample:

load * Inline [

id,name

1,abc

2,abcd

3,abcde

4,abcdef

];

I'm looking for a solution using which I would be able to create another field which will have spaces[' '] based on the length of the field 'name'. for example the table with the new field (fieldlen) should look like below

id,name,fieldlen

1, abc, '   '

2, abcd, '    '

3, abcde, '     '

4, abcdef, '      '

for id = 1 the fieldlen value should be 3 spaces and for id=2 the fieldlen value should be 4 spaces and so on.

Thanks in advance.

Thanks and Regards,

Sudeep

Tags (1)
1 Solution

Accepted Solutions
juleshartley
Valued Contributor

Re: Generating blank spaces based on field value length

Try

repeat(' ',len([name]))

6 Replies
juleshartley
Valued Contributor

Re: Generating blank spaces based on field value length

Try

repeat(' ',len([name]))

Not applicable

Re: Generating blank spaces based on field value length

Attached with answer. Its a little tedious, but once set up it will be good.

Thanks

kushalthakral
Contributor II

Re: Generating blank spaces based on field value length

Hi Ajay

your solution is good but what if we have 100 of records and having different combinations..

Regards

Kushal T

Not applicable

Re: Generating blank spaces based on field value length

It will still work. You just need to first set up for the 26 alphabets once. Once thats done, then the code is the same irrespective of the # of records.

kushalthakral
Contributor II

Re: Generating blank spaces based on field value length

Okk, we can simply write repeat with length statement in script so no need to create inline table

Regards

Kushal T

Not applicable

Re: Generating blank spaces based on field value length

Yeah. That seems like a simpler option. Mine is just another way of approaching the same issue.

Repeat() is definitely an ideal solution.

Community Browser