Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

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

INSERTING DASH "-" CHARACTER BETWEEN THE DIGITS

dunkindonut7777
8 - Asteroid

Hi how to transform these values into these one. (Expected_Code)

 

CodeExpected_Code
2020112020-11

202101

2021-01
2019032019-03

 

Can you help me with this one pls? Thank you

7 REPLIES 7
TheOC
16 - Nebula
16 - Nebula

hey @dunkindonut7777 

(nice name btw)

Please find attached a solution that uses the formula tool:

TheOC_0-1647854701919.png




Cheers,
TheOC

Cheers,
TheOC
Connect with me:
LinkedIn Bulien
AkimasaKajitani
17 - Castor
17 - Castor

Hi @dunkindonut7777 ,

 

You can use this expression in the Formula tool.

 

Left(ToString([Code]), 4)+"-"+Right(ToString([Code]), 2)

 

AngelosPachis
16 - Nebula

Hi @dunkindonut7777 ,

 

In a formula tool, you can try the following expression

 

LEFT([Code],4)+"-"+Right([Code],2)

 

That will work only if the Code column is a String, V_String etc. If it isn't already you can stick a select tool before the formula tool and change the data type or use the ToString function

LEFT(ToString([Code]),4)+"-"+Right(ToString([Code]),2)
Alteryx_AR
12 - Quasar

 @dunkindonut7777  Another option is using formula - 

 

Left(PadLeft([Code],6,"0"),4) + "-" + Right(PadLeft([Code],6,"0"),2)

Alteryx_AR
12 - Quasar

@dunkindonut7777  Use formula -

 

ArtiRajput_0-1647869962711.png

 

danilang
19 - Altair
19 - Altair

And there's always regex to consider

 

REGEX_Replace(tostring([Code]), "(\d{4})(\d{2})", "$1-$2")

danilang_0-1647887912657.png

 

Dan

rdlalli
6 - Meteoroid

I found this discussion helpful as I was trying to turn an 8-digit string of numbers into something that looked like a date (YYYYMMDD to YYYY-MM-DD).  The Regex comment was the one that helped me the most.  I just modified the formula to be used with 8 digits instead of 6.  I also needed to convert it to an EU formatted date like dd.mm.yyyy.  It can be done in a single step as shown in output columns named "New EU formatted.....", but I left the New Start and New Finish in there in case it helped anyone see the transition.

Labels
Top Solution Authors