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.

Transforming Data

cowannbell
9 - Comet

trI need to transform data from rows to columns.

 

So the group field is called PIN but then I have Lic #, Lic Type, Lic Date.

 

I need to include all lic fields on the same row as the pin.  How can I accomplish this?

 

So like this:

 

PinLic #Lic typeLic DateLic #Lic typeLic Date
1001Small1/1/20234Medium4/1/2023
2002Small2/1/20235Medium5/1/2023
3003Small3/1/20236Medium6/1/2023
9 REPLIES 9
jrgo
14 - Magnetar

I'm thinking the Crosstab tool, but column headers are required to be unique so they won't look like the way you pictured in your table.

 

If you can also share what your source/start data looks like, we may be able to provide a more detailed solution.

ed_hayter
12 - Quasar

We can use a combo of transpose and crosstab to do this once we make an identifier for new rows.

image.png

 

cowannbell
9 - Comet

I want all lice on the same row as the pin.  Your example has it on different rows. 

ed_hayter
12 - Quasar

Apologies - I see now that is your desired output. Can you quickly demonstrate what it would look like coming in

 

cowannbell
9 - Comet

Sure, actually exactly what you have in our output, without the record id. So I need the reverse.

ed_hayter
12 - Quasar

You can group by the pin and concatenate the other fields. This does not get exactly to your desired output of having the information in separate fields. To get that I used some brute force with text-to-columns splitting on the ",".

 

This works fine when there are only ever two of each but I'd need to spend more time thinking up a dynamic solution to split based on the number of records per pin. Suppose you could increase the split to a larger number than the maximum and then remove null columns. Potential problem is that you are making the data very wide and not as performant.

 

I'll leave the brute force one here and then give a smarter solution some thought.

 

image.png

The second workflow is one that expands the table and removes null columns

cowannbell
9 - Comet

I think I might have confused you.

 

Maybe this will help.

 

How data is      
      
          
PinLic #Lic TypeLic Date      
1001Small1/1/2023      
1002Medium1/1/2023      
1003Large3/1/2023      
2005Small 4/1/2023      
2007Medium5/1/2023      
2008Large6/1/2023      
30010Small2/1/2023      
30014Medium7/1/2023      
30023Large8/1/2023      
          
          
How I want it      
      
      
PinLic #Lic TypeLic DateLic #Lic TypeLic DateLic #Lic TypeLic Date
1001Small1/1/20232Medium1/1/20233Large3/1/2023
2005Small 4/1/20237Medium5/1/20238Large6/1/2023
30010Small2/1/202314Medium7/1/202323Large8/1/2023

 

cowannbell
9 - Comet

I think I might have confused you.

 

Hopefully the attached will help.

 

 
 

 

 

ed_hayter
12 - Quasar

The above Workflow would achieve that output - although you cannot have column headers with identical names - hence the suffix (LIC_1, LIC_2 ETC.). But the logic of bringing all that information onto the same row for each pin and then splitting on the list delimiter is likely the best way to achieve this.

 

 

The second part of my comment was more rambling about thinking of more dynamic ways of getting to the desired output (when pins have varying amount of LICs in them.)

Labels