cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
wolfy_ Regular Visitor
Regular Visitor

transform 1 column in 2 columns

Hi,

 

Is the a way to transform 1 column in 2 colunms every now and then value?

 

1column2columns.png

 

Columns1

2019-08-08 20:12:30.51
1F7D 09
2019-08-08 20:10:06.47
2045 09
2019-08-08 20:12:51.09
1F7E 09
2019-08-08 20:13:18.86
1FE3 09

 

to

 

columns1                                 columns2

2019-08-08 20:12:30.51          1F7D 09
2019-08-08 20:10:06.47          2045 09
2019-08-08 20:12:51.09          1F7E 09
2019-08-08 20:13:18.86          1FE3 09

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User I
Super User I

Re: transform 1 column in 2 columns

These Pivot challenges can be solved by using an additional column to identify the pairs.  This gets past the error thrown from Pivot when using 'Don't aggregate'.

 

Add an index column (from zero).

Add a column which identifies the pairs with                    each Number.IntegerDivide([Index],2)

Then delete the unneeded columns and do the pivot.

 

et
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dcw7CsAwDAPQq4TMrZGdv+emlwi5/zUagqdCQINAD43hBdxu1BUnUBYNoMR+XsPzWx6HtvuPQZEpFptiOjDRxGTTeusHFpQr1Wysh83mBw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Columns1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Columns1", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    #"Added Custom" = Table.AddColumn(#"Added Index", "data", each Number.Mod([Index], 2)),
    #"Added Conditional Column" = Table.AddColumn(#"Added Custom", "Custom", each if [data] = 0 then "datetime" else "id"),
    #"Added Custom1" = Table.AddColumn(#"Added Conditional Column", "Custom.1", each Number.IntegerDivide([Index],2)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Index", "data"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Custom]), "Custom", "Columns1")
in
    #"Pivoted Column"

It's a good technique if the data comes in a list with a consistent order.

 

 

View solution in original post

3 REPLIES 3
Highlighted
dearwatson Member
Member

Re: transform 1 column in 2 columns

Hi Wolfy,

 

this is a "pivot" challenge.

 

In power query create a new column that alternates the values:

column1

column2

 

then do a "pivot" on this new column with your original column as the value... this should give you the output you needs

 

Cheers

Greg

 

 

"The commonality between science and art is in trying to see profoundly - to develop strategies of seeing and showing." - Edward Tufte
wolfy_ Regular Visitor
Regular Visitor

Re: transform 1 column in 2 columns

Hi,

 

I tried as you said

2columns.png

 

But the result after pivot is not the expected

 

pivot.png

 

 

error_pivot.png

 

Super User I
Super User I

Re: transform 1 column in 2 columns

These Pivot challenges can be solved by using an additional column to identify the pairs.  This gets past the error thrown from Pivot when using 'Don't aggregate'.

 

Add an index column (from zero).

Add a column which identifies the pairs with                    each Number.IntegerDivide([Index],2)

Then delete the unneeded columns and do the pivot.

 

et
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dcw7CsAwDAPQq4TMrZGdv+emlwi5/zUagqdCQINAD43hBdxu1BUnUBYNoMR+XsPzWx6HtvuPQZEpFptiOjDRxGTTeusHFpQr1Wysh83mBw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Columns1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Columns1", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    #"Added Custom" = Table.AddColumn(#"Added Index", "data", each Number.Mod([Index], 2)),
    #"Added Conditional Column" = Table.AddColumn(#"Added Custom", "Custom", each if [data] = 0 then "datetime" else "id"),
    #"Added Custom1" = Table.AddColumn(#"Added Conditional Column", "Custom.1", each Number.IntegerDivide([Index],2)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Index", "data"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Custom]), "Custom", "Columns1")
in
    #"Pivoted Column"

It's a good technique if the data comes in a list with a consistent order.

 

 

View solution in original post

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

January 2020 Community Highlights

January 2020 Community Highlights

Make sure you didn't miss any of the things that happened in the community in January!

Top Solution Authors
Top Kudoed Authors