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
PatrickPerovan
Frequent Visitor

Columns to Rows - Same column many times in row

Hi all,

I tried to figure out how to adjust this table. I tried transpose, unpivot, pivot, group by but I kind of stuck here. Could someone help with that?

 

That is the table that I have it:

 

Column1Column2
CountryFR
Duration0:7:54
Log_File20230418_015218
CountryGB
Duration0:5:59
Log_File20230418_015203
CountryGB
Duration0:7:54
Log_File20230418_013410
CountryGB
Duration0:0:3
Log_File20230418_014015
CountryGB
Duration0:7:54
Log_File20230418_015218
CountryFR
Duration0:6:15
Log_File20230418_020644

 

I need to transform like that:

 

CountryDurationLog_File
FR0:7:5420230418_015218
GB0:5:5920230418_015203
GB0:7:5420230418_013410
GB0:0:320230418_014015
GB0:7:5420230418_015218
FR0:6:1520230418_020644
1 ACCEPTED SOLUTION

Hi @PatrickPerovan,

 

Instead of a custom column, copy the sample script.

Add a new blank query, open up the advanced editor - delete the let-expression in there and paste the code sample in.

 

Next replace the expression assigned to the Source step by a reference to the query with your production data. To illustrate if that query had the name "My Query" then it should look like below.

 

 

let
    Source = #"My Query",
    SplitTable = Table.Split( Source, 3),
    NewTable = Table.FromRecords( List.Transform( SplitTable, each Record.FromList( _[Column2], _[Column1])))
in
    NewTable

 

 

Hope this helps

View solution in original post

4 REPLIES 4
PatrickPerovan
Frequent Visitor

Thanks!

PatrickPerovan
Frequent Visitor

Hi @m_dekorte,

Many thanks! 😄

 

How to change reference using your code?

 

I posted an example here and when I tried to copy and paste using "Custom Column" it brings my example instead of my original table 😅

 

Hi @PatrickPerovan,

 

Instead of a custom column, copy the sample script.

Add a new blank query, open up the advanced editor - delete the let-expression in there and paste the code sample in.

 

Next replace the expression assigned to the Source step by a reference to the query with your production data. To illustrate if that query had the name "My Query" then it should look like below.

 

 

let
    Source = #"My Query",
    SplitTable = Table.Split( Source, 3),
    NewTable = Table.FromRecords( List.Transform( SplitTable, each Record.FromList( _[Column2], _[Column1])))
in
    NewTable

 

 

Hope this helps

m_dekorte
Super User
Super User

Hi @PatrickPerovan,

 

You could give this a go.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs4vzSspqlTSUXILUorViVZyKS1KLMnMzwOKGFiZW5magEV98tPj3TJzUoGiRgZGxgYmhhbxBoamRoYWYGmEKe5OmKaYWpla4jXFwJgIUwi4xdjE0IAIUwysjPEYYgJ0DeVOwRIs2ALXzApqGVZTjAzMTICWxAIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    SplitTable = Table.Split( Source, 3),
    NewTable = Table.FromRecords( List.Transform( SplitTable, each Record.FromList( _[Column2], _[Column1])))
in
    NewTable

 

with this result

m_dekorte_0-1681854034233.png

I hope this is helpful

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.

Top Solution Authors
Top Kudoed Authors