Alteryx Designer Desktop Discussions

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

Formula Split at Hyphen

mattcoleman
8 - Asteroid

Pretty simple request that I can't seem to get working.

 

I have data that varies in length, but there is a hyphen and I only want what's before the hyphen. I'm guessing I should be using a Formula tool?

 

EXAMPLE: Factory Cost Centers-Business Admin....all I want is Factory Cost Centers. The hyphen always defines the split.

 

Thanks in advance!!!

3 REPLIES 3
jrgo
14 - Magnetar

Hi @mattcoleman,

 

You can use the RegEx_Replace() function within the formula tool to do so. Here's the expression:

REGEX_REPLACE([Field],'^(.+?)-.*$','$1')

Without going too much into details, this regex is saying from the start of the string, capture all characters until it finds the first '-'.

 

Hope this helps!

 

Jimmy

mattcoleman
8 - Asteroid

Worked perfectly, thanks Jimmy!

KaneG
Alteryx Alumni (Retired)

Without REGEX you could try

 

Left([Field],Findstring([Field],'-'))

 

That will find the character number of the hyphen and take the left characters before it

Labels