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

Remove everything after the first hyphen from the right

rahulshetty925
8 - Asteroid

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

9 REPLIES 9
StephenR
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
Principal Customer Support Engineer

Claje
14 - Magnetar

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.

ponraj
13 - Pulsar

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

 

InputInputWorkflowWorkflowResultsResults

rahulshetty925
8 - Asteroid

Hi Claje,

 

Both the solutions worked in my case.Thank You.

 

I was probably not reversing the string.

 

Regards,

Rahul Shetty

rahulshetty925
8 - Asteroid

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

rahulshetty925
8 - Asteroid

Hi Ponraj,

 

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

 

Regards,

Rahul

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

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

Regards,
Stephen Ruhl
Principal Customer Support Engineer

Murugan
5 - Atom

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

Labels