Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
wolfy_
Helper I
Helper I

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

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
dearwatson
Responsive Resident
Responsive Resident

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

Hi,

 

I tried as you said

2columns.png

 

But the result after pivot is not the expected

 

pivot.png

 

 

error_pivot.png

 

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.

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.