Alteryx Designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
Don't forget to submit your entry for the Excellence Awards by October 30! | Need more information about the program? Check out the blog here
SOLVED

Remove everything after the first hyphen from the right

Highlighted
Alteryx Partner

Hi All,

 

I have been trying to remove everything after first - from the right of a string including the -

 

Example My string has

INPUT:                                              Output;

 

ABC-DEF-GHI                                 ABC-DEF

JHX-HZXE                                       JHX                           

HDKDK12-HJDJ-7695                   HDKDK12-HJDJ  

 

 Requirement is to always remove everything from the first - right of the string.

 

I have tried Right([account], FindString([account], '-')) and some regex functions but nothing is giving me the right result.

 

 

 

Let me know if anyone can help.

 

Regards,

Rahul

Highlighted
Alteryx
Alteryx

I would use Text to Columns and split on "-". You only need to split to two fields and the result you want will be in the first field while everything else will split out into the second field.

Regards,
Stephen Ruhl
Customer Support Engineer

Highlighted
ACE Emeritus
ACE Emeritus

Hi,


Here's a regular expression that should work:

(.*)-[^-]*

This will output all data before a dash that has only non-dash characters after it.

 

Additionally, a formula option is below:

Left([Account],Length(Account)-FINDSTRING(ReverseString(Account),'-')-1)

This will take the left characters up until a character before the last "-" in the string, thanks to ReverseString.

Highlighted
13 - Pulsar

Here is the sample workflow for your case. Hope this is helpful. 

 

InputInputWorkflowWorkflowResultsResults

Highlighted
Alteryx Partner

Hi Claje,

 

Both the solutions worked in my case.Thank You.

 

I was probably not reversing the string.

 

Regards,

Rahul Shetty

Highlighted
Alteryx Partner

Hi Sruhl,

 

I had laready tried this one.The problem with this one was the split in to first and second was not what I required.

 

For example -- output was getting split after the first hyphen.

 

Regards,

Rahul

Highlighted
Alteryx Partner

Hi Ponraj,

 

This looks like a good hack for my question. Thanks very much.

 

Regards,

Rahul

Highlighted
13 - Pulsar
You can mark it as a solution if u think that the solution I provided is ideal one for your case.
Highlighted
Alteryx
Alteryx

@rahulshetty925I see, I missed that important piece. I'm glad you got a solution.

Regards,
Stephen Ruhl
Customer Support Engineer

Highlighted
5 - Atom

hey can u pls share your solved code ..becoz your .yxmd file is not opening ...share in  notepad or readable format

Labels