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

Cross-tab or Transpose of blocks of columns (load data into excel)

timewaste
8 - Asteroid

Hi Peers,

 

I am trying to transpose the data into 3 sets to write back in to excel. Please see below for my source data:

 

VEDDFSFSPHTH
RBGNCTePHM14.4
RBGNCTePHA1.6
RBGNCTePHV0
RBANCBuPHM16
RBANCBuPHA0
RBANCBuPHV0
RBANCZiPHM0
RBANCZiPHA0
RBANCZiPHV0

 

and my output must look like:

 

 VRRRRRRRRR
 EDBBBBBBBBB
 DGGGAAAAAA
 FNCNCNCNCNCNCNCNCNC
 SFTeTeTeBuBuBuZiZiZi
 TMAVMAVMAV
SPHPH14.41.601600000

 

How can I achieve this? Please advise.

 

TIA!

13 REPLIES 13
garthheward
7 - Meteor

I think you can get most of the way to your result with the TotallyTranspose macro.

 

After running that on your data, it's just a shift of your PH/SPH names

danilang
19 - Altair
19 - Altair

hi @timewaste

 

Like @garthheward mentioned, the Totally Transpose macro will get you close, but you need to add a record ID column for the macro to use as output column names.  Also, the macro row output is alphabetical by the 1st column,  like so

 


ED 


SF 
SPH 

 

You want them in original column order starting with the V row.  In order to easily do this, you'll need to a column order column after the transpose inside the Macro.  Since debugging macros is tricky, I've attached a standard workflow that gives the output you want.

 

Solution.png

 

Dan

timewaste
8 - Asteroid

@danilang Wow! U made it look so simple. Thanks a ton! @garthheward Sure, will check it out.

timewaste
8 - Asteroid

@danilang So in my real case, I have total of 266544 records as input. When I am processing using above workflow, I have noticed that at cross-tab stage, it would need to generate more than 1000 fields(columns), hence throwing an exception:

 

Warning: Cross Tab (19): More than 1000 fields are being generated by the CrossTab

 

Is there an alternative approach to this at that step? Or can I reset the configuration somewhere to accommodate all the fields. In my data set, I would have total of 33318 fields after cross-tab stage in output (just fyi based on my data). 

 

Please advise.

 

TIA!

danilang
19 - Altair
19 - Altair

Hi @timewaste

 

With 266544 records as input, you should get that many columns as output after the cross tab unless you get duplicates, in which case, the values will be concatenated. 

 

You're also running up against an excel limit, here.  You can only have 16,384 columns in an excel sheet.  

 

Maybe you could explain what your overall goal is.  Why do you need to crosstab?  Is there a reason you can't work with the data in row order as opposed to column order?  That many columns in excel can't be for human consumption.  Do you have a pivot table or graph output that requires the data in that form?

 

Dan 

 

 

timewaste
8 - Asteroid

@danilang Yes, my bad, I filtered the data to not include zeros and could bring down the data set to ~21000 rows and could perform crosstab. So, here's my situation. My data has multiple possibilities to grow. It was my bad that I gave a sample which was one dimensional above. Here's how the data would actually look like:

 

VEDDFSFSPHTH
RBGNCTePHM14.4
RBGNCTePHA1.6
RBGNCTePHV0
RBGNCTeAP1M2.5
RBGNCTeAP1A6
RBGNCTeAP1V0
RBANCBuHP1M16
RBANCBuHP1A0
RBANCBuHP1V0
RBANCZiPH2M0
RBANCZiPH2A8
RBANCZiPH2V0

 

So, the values in SPH column can vary and come in as input data in multiple combinations as shown above (in colors pink/black and red denotes change in values in SPH column). So, from your solution... at the formula tool stage (in adding PreName, Name and ColID), how can I make sure that it dynamically picks the value in SPH and assigns it to Name filed in the output as shown below?

 

Alteryx Use Case.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 VRRRRRRRRR
 EDBBBBBBBBB
 DGGGAAAAAA
 FNCNCNCNCNCNCNCNCNC
 SFTeTeTeBuBuBuZiZiZi
 TMAVMAVMAV
SPHPH14.41.60000000
SPHAP12.560000000
SPHHP10001600000
SPHPH2000000080

 

Please advise. Thanks a ton!

timewaste
8 - Asteroid

@danilang I am not sure if you received my previous response but I dont seem to find it on the thread here. Anyways, here's the actual question:

 

Yes, I was able to figure out the cross tab step. I removed all values that are equal to 0 and was able to limit the rows that I need to work on but, the challenge I face now is to get to the right output as shown below for multiple combinations of SPH in input data.

 

Input Data:

 

VEDDFSFSPHTH
RBGNCTePHM14.4
RBGNCTePHA1.6
RBGNCTePHV0
RBGNCTeOP1M14.4
RBGNCTeOP1A1.6
RBGNCTeOP1V0
RBGNCTe1PHM2.5
RBGNCTe1PHA6
RBGNCTe1PHV0
RBGNCTe1AP1M2.5
RBGNCTe1AP1A6
RBGNCTe1AP1V0
RBANCBuHP1M16
RBANCBuHP1A0
RBANCBuHP1V0
RBANCZiPH2M8
RBANCZiPH2A8
RBANCZiPH2V0

 

And the output data must look like:

 

PreNameName123456789101112
 VRRRRRRRRRRRR
 EDBBBBBBBBBBBB
 DGGGGGGAAAAAA
 FNCNCNCNCNCNCNCNCNCNCNCNC
 SFTeTeTeTe1Te1Te1BuBuBuZiZiZi
 TMAVMAVMAVMAV
SPHPH14.41.60000000000
SPHOP114.41.60000000000
SPHPH0002.560000000
SPHAP10002.560000000
SPHHP10000001600000
SPHPH2000000000880

 

and so on... Please advise. Thanks a ton!

 

 

danilang
19 - Altair
19 - Altair

Any chance you could recreate the missing message. It's got some details that sound important.  I've just got the text in my inbox with no images. Secifically this part

", the values in SPH column can vary and come in as input data in multiple combinations as shown above in colors blue and black and red denotes change in values in SPH column"

 

 

So your output will look like this

 

 

PreNameName123456789101112
 VRRRRRRRRRRRR
 EDBBBBBBBBBBBB
 DGGGGGGAAAAAA
 FNCNCNCNCNCNCNCNCNCNCNCNC
 SFTeTeTeTe1Te1Te1BuBuBuZiZiZi
 TMAVMAVMAVMAV
SPHPH14.41.60000000000
SPHOP114.41.60000000000
SPHPH0002.560000000
SPHAP10002.560000000
SPHHP10000001600000
SPHPH2000000000880

 

but with 30,000 columns?  Or have gotten the output down to a reasonable number of columns?

 

Dan

 

 

 

 

timewaste
8 - Asteroid

@danilang Well, you can ignore the entire message or even missing piece of the message. Essentially, what I wrote in that message was you can ignore 30,000 columns issue I face. I was able to cut down the data to few thousands of columns (5312 columns) by using a filter tool. So, I am good there.

 

The problem I am facing is at the formula tool step - populating PreName and Name columns. I mean if my source data doesn't have just "PH", rather has multiple values like "PH", "PH1", "OP1", "AP1" so on in SPH column for the same combination (V --> ED --> D --> F --> SF)... I have highlighted one use case in Orange and all different values in Red... what do I do? How do I populate output data shown below based on below input data?

 

Input Data:

 

VEDDFSFSPHTH
RBGNCTePHM14.4
RBGNCTePHA1.6
RBGNCTePHV0
RBGNCTeOP1M14.4
RBGNCTeOP1A1.6
RBGNCTeOP1V0
RBGNCTe1PHM2.5
RBGNCTe1PHA6
RBGNCTe1PHV0
RBGNCTe1AP1M2.5
RBGNCTe1AP1A6
RBGNCTe1AP1V0
RBANCBuHP1M16
RBANCBuHP1A0
RBANCBuHP1V0
RBANCZiPH2M8
RBANCZiPH2A8
RBANCZiPH2V0

 

And the output data must look like:

 

PreNameName123456789101112
 VRRRRRRRRRRRR
 EDBBBBBBBBBBBB
 DGGGGGGAAAAAA
 FNCNCNCNCNCNCNCNCNCNCNCNC
 SFTeTeTeTe1Te1Te1BuBuBuZiZiZi
 TMAVMAVMAVMAV
SPHPH14.41.60000000000
SPHOP114.41.60000000000
SPHPH0002.560000000
SPHAP10002.560000000
SPHHP10000001600000
SPHPH2000000000880

 

and so on... Please advise. Thanks a ton!

Labels
Top Solution Authors