Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
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

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