Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

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

Numeric Like Text Format Conversion

Ewbkm
7 - Meteor

Hi,

I have the cost center data, which come in as text data type and I need to convert the cost center in numeric form to be three digits format (1 to 001 and 22 to 022) and keep the cost center with text name as the way it is (e.g. HQ still shows as HQ).  The data and desired results are as below: 

COST CENTERDESIRED FORMAT
1001
128128
130130
555555
22022
60060
4004
CALL CENTERCALL CENTER
HQHQ

Is there any formula can help me to do the conversion?

Thanks.

4 REPLIES 4
Qiu
20 - Arcturus
20 - Arcturus

@Ewbkm 
First we can check if the length of the text is below 3 or not. 
If yes, a PadLeft function can be used.

0416-Ewbkm.PNG

danilang
19 - Altair
19 - Altair

Hi @Qiu 

 

Small error in your formula causing HQ to become 0HQ.  Change your condition to use regex_match looking for a digit as the first character

if regex_match([COST CENTER],"\d.*") then 
   PadLeft([COST CENTER], 3, '0') 
else 
   [COST CENTER] 
endif

 Dan

Qiu
20 - Arcturus
20 - Arcturus

@danilang 
Thank you so much for pointing it out.
So sorry missing that out.

binuacs
20 - Arcturus

@Ewbkm another way of doing is with the IsInteger() function

 

binuacs_1-1650114784436.png

 

 

 

 

IIF(IsInteger([COST CENTER]),PadLeft([COST CENTER], 3, '0'),[COST CENTER])

 

binuacs_0-1650114617724.png

 

Labels