Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Concating string based on the condition of sting length

edward_chow
5 - Atom

Hello! 

 

I recently got the below dataset and would like to do some transformation:

 

NameGroup No
John123
Sam5647
Apple000458
Shally679412

 

For the column `group no`, I have to make sure the length is 6. If this is not the case, we add '0's before the string.

 

So I try to write the below formula but it does not work

 

 

IF Length([Group No]) < 6
THEN (6 - Length([Group No]) * "0" + [Group No]
ELSE null()
ENDIF

 

 

 

The expected result would be: 

 

NameGroup No
John000123
Sam005647
Apple000458
Shally679412

 

Any ideas on how to do that are highly appreciated.

 

Thank you,

3 REPLIES 3
flying008
14 - Magnetar

Hi, @edward_chow 

 

This is your want ?

flying008_0-1677647875222.png

 

 

PadLeft([Group No], 6, "0")

 

******

If it can help you , please mark it as a solution and give a like for more share.

 

niteshsharma677
7 - Meteor

Hi @edward_chow 

You can use the PadLeft Function in the Formula tool to get the desired result like below. 

Formula - PadLeft([Group No], 6, '0')

Alteryx Query 1 Solution.PNG

ShankerV
17 - Castor

Hi @edward_chow 

 

One way of doing this is with the help of padleft function.

 

PadLeft([Group No], 6, '0')

 

ShankerV_1-1677649721158.png

 

 

Note: Padleft function works only on the String datatype.

If your column Group No is Numeric datatype. Please convert into String datatype using Multi Field Formula as below.

 

ShankerV_2-1677649748323.png

 

Many thanks

Shanker V

Labels