Alteryx Designer Desktop Discussions

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

Converting list of strings to dummy variables

naomirht
5 - Atom

Hi Everyone, 

 

I'm new to Alteryx and would like to create dummy variables from a list of strings contained in one field.

 

How can I go from this table:

 

IDProduct_type
1A_C_B
2B_C
3D
4E_A
5F

 

to this one:

 

IDProd_AProd_BProd_CProd_DProd_EProd_F
111100
201000

3

000100
4100010
5000001

 

Given my basic knowledge of Alteryx, I would really appreciate a solution without applications.

 

Thank you in advance for your assistance,

2 REPLIES 2
MarqueeCrew
20 - Arcturus
20 - Arcturus

@naomirht,

 

Here's my thought process.  You want to parse the product type data with the underscore.  Now you don't know how many types that you will find.  That happens to be a good thing.  You can parse the data to ROWS.  Now each set of ID + Type gets it's own record.  For each record that does exist, we will create a new field "Value" and set it to 1.  We're vertical and have lots of 1's.  Now go HORIZONTAL and create a header record for each type that exists.  Using the cross tab  tool, you'll create all product types as HEADERs and all known 1's as values.  Where a product doesn't exist for a given ID, it is Null.  Now you can use a multi-field formula to turn all nulls to 0's.

 

Sounds easy enough....

 

capture.png

 

Guess what?  It worked!

 

If you want to add "Product_" as a prefix to the field names, then in the formula you can modify the "NAME" value with:

"Product_"+[Name]

 

Cheers,

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
naomirht
5 - Atom

Hi Mark,

 

Thank you very much for your solution! It worked!

Labels