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: 
Not applicable

Adding spaces to a field value

Hello all,

I have been searching the community but didn't find an answer.

I'm loading a field with a numeric value, but it can be considered as a string as it is a code which I display in the front-end.

Some values have a length of less then 6 characters.

They should at minimum be 6 characters. It could be they have more then 6 characters.

How do I do this in the script, adding a prefix (spaces) so the figure has 6 characters unless the figure is 6 or more then 6 long?

Example '123' should become '   123' but '1234567' should stay '1234567'

Thanks in advance for your help

Niels

Labels (1)
6 Replies
Not applicable
Author

num(number1,'     ') as number2

Not applicable
Author

or

if(len(number1)>5,number1,num(number1,'     ')) as number2

daveamz
Partner - Creator III
Partner - Creator III

Hello,

Try something like:

if(len(field)<6,  repeat(' ',(6-len(field)))&field, field) as field2

See the example attached.

Good luck!

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

I think this is simpler:

     =right('       ' & field, 7)

Regards

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
daveamz
Partner - Creator III
Partner - Creator III

Right, but what if the field has 8 or more characters? Then '12345678' will become '1234567'

jonathandienst
Partner - Champion III
Partner - Champion III

Well, if you want to pad out to 8 characters, then

     =right('        ' & field, 😎

It all depends on the data specification...

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein