community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

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

Delete the last part of the string

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!

Alteryx Certified Partner
Alteryx Certified Partner
trimright([field],"-301")

Ben

Asteroid

It doesn't work 

inputoutput
5587-838384-2235587-838384-22
555-33-331555
Alteryx Certified Partner
Alteryx Certified Partner

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
Alteryx Certified Partner

Maybe use an if statement?

 

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

Alteryx Certified Partner
Alteryx Certified Partner

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!

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

 

Alteryx Certified Partner
Alteryx Certified Partner
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
Highlighted
Alteryx Certified Partner

Did you try the sample?

 

Just plug the data into the workflow. and run

Labels