Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

Contain Formula

Devika
8 - Asteroid

Hello,

 

I wanted to separate and classify the data according to the below input and output

the trade ref that contain D is the domestic trades and trade ref that contains I is international 

INPUT

 

Trade Refs (Ours)     
D345447 (000005)
D343792 (000005)
D527015 (002884)
D520288 (002884)
D520288 (002884)
I129702 (000005)
I129702 (000005)
D418531 (000005), D420345
D428163 (000005), D428920
D402199 (083004), D523515(083004), D317365 (083004),D325464 (083004), D419502(000005), D525641 (000005)

 

Output 

 

Trade Refs (Ours)     Dom/Intl
D345447 (000005)Domestic
D343792 (000005)Domestic
D527015 (002884)Domestic
D520288 (002884)Domestic
D520288 (002884)Domestic
I129702 (000005)Intl
I129702 (000005)Intl
D418531 (000005), D420345Domestic
D428163 (000005), D428920Domestic
D402199 (083004), D523515(083004), D317365 (083004),D325464 (083004), D419502(000005), D525641 (000005)Domestic
5 REPLIES 5
grchavarri
11 - Bolide

Hi @Devika 

 

You can use an if in the formula tool including the function Contains

 

ie. 

if Contains(Trade Refs (Ours),"(000005)") then "Intl" else "Domestic" endif

 

Hope it helps. 

 

Best,

Kenda
16 - Nebula
16 - Nebula

Hi @Devika 

 

Here you can use a formula tool to create a new field. Based on the title of this post, it seems like you are close. The contains formula first needs to know what string you're looking in, then what you're looking for. Something like this:

contains([Trade Refs (Ours)], "D")

 

To create the output field you want, try wrapping this in an if statement!

binuacs
21 - Polaris

@Devika 

 

IIF(Left([Trade Refs (Ours)     ], 1) == 'D', 'Domestic', 'Intl')

 

binuacs_0-1647432341330.png

 

Kenda
16 - Nebula
16 - Nebula

Alternatively, if the first character of your field is always going to be either I or D, you could try the substring function:

substring([Trade Refs (Ours)],0,1)

 

This looks at the string you specify then it says start at the 0th character and keep only 1 character. To get your new field, just check if this is equal to D or I.

MarqueeCrew
20 - Arcturus
20 - Arcturus

I like @Kenda alternatives so I'll add one:

 

IIF(StartsWith([Trade Refs (Ours)], "D"),"Domestic","International")

 

That was fun 🤣@Devika , I hope that you enjoy the variety of solutions presented here.

 

Cheers,

 

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
Labels