In case you missed the announcement: The Alteryx One Fall Release is here! Learn more about the new features and capabilities here
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests after December 31, 2025. Set up your security questions now so you can recover your account anytime, just log out and back in to get started. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

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

Trim first two characters from a String

ssripat3
8 - Asteroid

Hello Community,

 

I have the below data and I am using a formula currently to trim the '-' if the Code column is empty and populate it similar to this value - D20240130 using the below formula.

 

IF !IsEmpty([Date]) AND IsEmpty([Code]) THEN "D" + Replace([Date], '-', '') ELSE
[Code]
ENDIF

 

Now, I am trying to add another condition which removes the value '20' from the left. When I add a TrimLeft to the above formula, it is removing more characters than required.

 

Table 1

CodeDate
ABC1232022-02-21
 2024-01-30
DEF1232023-11-30
 2020-03-15
 2020-11-27
GHI1232025-11-10
 2026-05-20

 

Table 2

CodeDate
ABC1232022-02-21
D2401302024-01-30
DEF1232023-11-30
D2003152020-03-15
D2011272020-11-27
GHI1232025-11-10
D2605202026-05-20

 

Can anyone suggest on how to achieve this?

1 REPLY 1
Mathias_Nielsen
9 - Comet

Hi @ssripat3 ,

Try this:

IF !IsEmpty([Date]) AND IsEmpty([Code]) THEN "D" + REGEX_Replace( Replace([Date], '-', ''), "^20","") ELSE
[Code]
ENDIF

 

I added a regexreplace that will remove the "20" from the front of the text string :)

Labels
Top Solution Authors