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

Field Formatting | Specific No. of Digits

JBO
8 - Asteroid

I have a field that must have 7 digits separated by a hyphen, like this:  XXXX-XXX

In and ideal world, my values would all contain 7 digits and I would only need to insert the hyphen, which I know how to do. Unfortunately, there are values missing up to 3 leading zeros.

Is there a way to:

(a)  set the number of digits required in a field, then

(b)  if the min required number of digits isn't met, prepend the value with the necessary number of zeros, and then

(c)  insert the hyphen (which I know how to do with a formula).

The result would be that values with fewer than 7 digits in the source data, such as 1001, would be converted to a hyphenated 7-digit value, such as 0001-001.

 

I am a new user and have limited experience.

3 REPLIES 3
MarqueeCrew
20 - Arcturus
20 - Arcturus

Step 1:  remove the -

 

Replace([field],"-",'')

 

step 2: pad zeros

 

padkeft(Replace([field],"-",''),7,"0")

 

step 3 insert -

 

left(padkeft(Replace([field],"-",''),7,"0"),4) + "-" +

right(padkeft(Replace([field],"-",''),7,"0"),3)

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
JBO
8 - Asteroid

This worked great. The only thing I did differently was swap padkeft with padleft.  Thank you so much for the speedy response.

MarqueeCrew
20 - Arcturus
20 - Arcturus
My iPhone 📱 solutions need a caveat. 🤓
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
Labels