Alteryx Designer Desktop Discussions

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

Split a coloumn into different coloumns

SZ
7 - Meteor

I have one column with data in it. I have an sql query and data underneath then another sql query and the output underneath etc.

 

I need to split the data from one sql query to another. 

 

Is there a way to do this?

10 REPLIES 10
ChrisTX
15 - Aurora

Can you post sample input and desired output?

SZ
7 - Meteor

I wish to use the word =============== SQL ================ as like a delimiter to split my data.

 

 

 

 

input sample:

 

 

Field_1

=============== SQL ================

<query>

============= RESULT ===============

userid;amount;type

1;10;bet

2;20;win

=============== SQL ================

<query>

============= RESULT ===============

userid;amount;type

20;33;bet

=============== SQL ================

<query>

============= RESULT ===============

userid;amount;type

66;9;bet

 

Desired output:

 

Field_1

Field_2Field_1

=============== SQL ================

<query>

============= RESULT ===============

userid;amount;type

1;10;bet

2;20;win

=============== SQL ================

<query>

============= RESULT ===============

userid;amount;type

20;33;bet

=============== SQL ================

<query>

============= RESULT ===============

userid;amount;type

66;9;bet

 

 

afv2688
16 - Nebula
16 - Nebula

You could add to each query a column, like an id, and after transpose the result using this field as key field.

SZ
7 - Meteor

@AFTV2688 add an id to each coloumn like 1,2,3,4,5 etc? I have a large data so I can not do that cause it's impossible to know which id is the same row to the query

afv2688
16 - Nebula
16 - Nebula

Use a macro to add to each query a unique id, which is going to be the same value for every row of your query:

 

Query         Value

1                    1

1                    2

1                    3

1                    4

2                    1

2                    2

2                    3

2                    4

etc

 

afterwards use the transpose tool using the "Query" as key field.

estherb47
15 - Aurora
15 - Aurora

Hi @SZ !

Yes. My approach involves a bit of Regex and formula magic. 

The Regex splits your single cell into distinct rows. It looks to parse on = followed by SQL. The first row is junk so we can discard, and then a Record ID tool is used to assign "rows". That info will be used to build the horizontal table in the crosstab.

A Formula tool reinserts the = characters removed by Regex. And a crosstab tool transposes from rows into columns.
image.png

Please give it a go and let me know if this works.

Cheers! 
Esther

jdunkerley79
ACE Emeritus
ACE Emeritus

I would user MultiRow formula tools to make row and column ids then cross tab

 

2019-03-12_18-14-45.jpg

 

The first multi row formula will create a column counter adding one every time SQL line is found

The second is grouped by the output of the first to create a row id

Finally a Cross Tabs makes the table

 

Sample attached

estherb47
15 - Aurora
15 - Aurora

EDITED: I see @jdunkerley79  and I took a very similar approach. Either will work if the data is in separate rows in your original sample.

@SZ , are all of the data in one cell, or does your information represent separate rows? My first approach parses if it's all in one cell.

If different rows, then this should work:
image.png

SZ
7 - Meteor

Capture.PNG

 

@jdunkerley79 it didn't work this is my output.

 

 

Labels