Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

Delete the last part of the string

Nastya
8 - Asteroid

Hello everyone!

I have the following problem:

I need to delete the last number after "-" only if it's equal to 301 

For example

222-444-301222-444
222-444-555222-444-555

Thanks!

8 REPLIES 8
BenMoss
ACE Emeritus
ACE Emeritus
trimright([field],"-301")

Ben

Nastya
8 - Asteroid

It doesn't work 

inputoutput
5587-838384-2235587-838384-22
555-33-331555
BenMoss
ACE Emeritus
ACE Emeritus

I'm not sure what is going on with that statement...

 

This one definitely does.

 

if
right([input],3) = "301"
then
Left([input],Length([input])-4) 
else [input] 
endif
j_acon
9 - Comet

Maybe use an if statement?

 

if(Right([Field1],4) = "-301")
Then
left([Field1],Length([Field1]) - 4)
else
[Field1]
endif

BenMoss
ACE Emeritus
ACE Emeritus

Okay so it looks like the trimright([field],"-301") function was looking for any of the characters in -301 at the end of the string and replacing them with nothing; I thought it would do the entire string only.

 

Anyway, the second solution I have provided should be adequate!

 

Always learning!

Nastya
8 - Asteroid

sorry for poor data. There can be any length of the row. 

Let me show some more examples

InputOutput
388-999-333-301388-999-333
565-333-301-555-301565-333-301-555
388-888-301-301388-888-301

 

BenMoss
ACE Emeritus
ACE Emeritus
Hi! Irrespective of the length of the strings both the solutions provided above should be dynamic and cater for this, are they not working for you?

Ben
j_acon
9 - Comet

Did you try the sample?

 

Just plug the data into the workflow. and run

Labels