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

Alteryx Designer Desktop Discussions

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

Parse Comma separated values in multiple columns to multiple columns

Praneeth
5 - Atom

Hello all,

 

I need your help and suggestions with the following scenario. I have the following file 

 

IDFruit#Day
1Apple, Banana, Mango1,2,3,4Mon, Tue
2Apple, Banana, Mango, Kiwi1,2,3,4,5,6Tue, Wed, Thu, Fri
3Apple, Banana1,2,3Tue, Wed, Mon, Sun
4Apple, Banana, Mango, Plums1,2,3,4,5,6,7Tue, Wed, Mon, Sun
5Apple, Banana, Mango, Strawberry2,3,4,5,6Mon, Tue, Wed, Thu, Sat

 

My requirement is to split these values to different columns like below. 

 

IDFruit_1Fruit_2Fruit_3Fruit_4#_1#_2#_3#_4#_5#_6Day_1Day_2Day_3Day_4Day_5
1Apple Banana Mango 1234  Mon Tue   
2Apple Banana Mango Kiwi123456Tue Wed Thu Fri 
3Apple Banana  123   Tue Wed Mon Sun 
4Apple Banana Mango Plums123456Tue Wed Mon Sun 
5Apple Banana Mango Strawberry23456 Mon Tue Wed Thu Sat

 

I understand we can use text-to-columns to get this output, but let's say I have 40 columns and I have to de-limit those values? Can't think of a solution. Can anyone help?

3 REPLIES 3
danilang
19 - Altair
19 - Altair

Hi @Praneeth 

 

As is usually the case when dealing with multiple columns, the best strategy is to transpose all the columns you want to work on, perform the operation on the single pair of columns and Cross tab to get the final grid.

 

w.png

After transposing, split the value field to rows, and then number them sequentially within each group with the Multi row formula tool.  Use a formula tool to generate the final header names.  I replaced # with aaaaaa a since the Cross tab tool replaces non alpha and digit characters with underscore.  After the Cross Tab, rename the aaaaaa_ columns to #_

 

r.png 

Another fun thing the Cross tab tool does is order the columns alphabetically.  You can produce the output in the original column order, but since you have varying numbers of items in the concatenated string, the logic will be quite complex.

 

Dan 

Praneeth
5 - Atom

Thanks so much! works perfectly fine! 

jroddy
5 - Atom

Pure Genius! That was exactly what I was looking for. Thanks.

Labels
Top Solution Authors