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

How To: Adding part of a value to another value

Czaggy
7 - Meteor

Hello everyone,

 

I have the columns "tag" and "ID" and want to combine them together in a new output column, but only if the tag starts with a number. The first part of the tag should be added to the ID with an aidditional "_". However, the first part can vary in length till it reaches the first "-". I tried using the formula tool and using the STARTSWITH() function or the regex but I do not seem to get any useful result. If adding a flexible string is not possible, I would be fine with adding it manually, sort of like this

If "tag" startswith 82 then add "_82" 

 

If the tag does not start with a number like "82" then the ID remains untouched.

 

Is there someone who can help me out here? I'd really appreciate it 🙂

 

TagIDOUTPUT COLUMN
82-S8.24545_82
82-F8.24545_82
8210-S8.2.104545_8210
8210-F8.2.104545_8210
83-S8.34545_83
83-F8.34545_83
90-S9.04545_90
90-F9.04545_90
91-S9.14545_91
91-F9.14545_91
82-S8.25050_82
82-F8.25050_82
8210-S8.2.105050_8210
8210-F8.2.105050_8210
83-S8.35050_83
83-F8.35050_83
90-S9.05050_90
90-F9.05050_90
91-S9.15050_91
91-F9.150

50_91

RHS60

60

Random60

60

4 REPLIES 4
LordNeilLord
15 - Aurora

Hey @Czaggy 

 

Would something simple like:

 

ID+"_"+Left([Tag], FindString([Tag],"-"))

 

Work for you?

Czaggy
7 - Meteor

Hey @LordNeilLord,

 

YES! I am really close to what I was looking for.

 

Is there a possibility to apply this rule only to "Tag" values that start with a digit (0-9)? Otherwise I receive IDs that just have the "_" addition without anything following up,

 

I cannot thank you enough!

LordNeilLord
15 - Aurora

Hey @Czaggy 

 

Try this:

 

if REGEX_Match(Left(Tag, 1), "[0-9]")
Then toString(ID)+"_"+Left([Tag], FindString([Tag],"-"))
Else Null()
Endif

Czaggy
7 - Meteor

Thank you very much! I solved it filtering for values that start with a number first, but your solution is even cleaner.

Thank you @LordNeilLord 

Labels