Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Administrator
5 years ago
Solved

structure table

Good morning, I need to convert a table into a power query editor as follows:

Initial table:

nullnullmes1mes1mes2mes2mes3mes3
null nullfirst fortnightsecond fortnightfirst fortnightsecond fortnightfirst fortnightsecond fortnight
person 1tipo1123456
persona1tipo25843825
person 2tipo1123456
persona2tipo25843825
person 3tipo1123456
persona3tipo25843825

Table to get:

personguymyfortnightvalue
persona1tipo1mes1first fortnight1
persona1tipo1mes1 second fortnight2
persona1tipo1mes2first fortnight3
persona1tipo1mes2second fortnight4
persona1tipo1mes3first fortnight5
persona1tipo1mes3second fortnight6
persona1tipo2mes1first fortnight5
persona1tipo2mes1 second fortnight8
persona1tipo2mes2first fortnight4
persona1tipo2mes2second fortnight3
persona1tipo2mes3first fortnight8
persona1tipo2mes3second fortnight25
persona2tipo1mes1 first fortnight1
persona2tipo1mes1 second fortnight2
persona2tipo1mes2first fortnight3
persona2tipo1mes2second fortnight4
persona2tipo1mes3first fortnight5
persona2tipo1mes3second fortnight6
persona2tipo2mes1first fortnight5
persona2tipo2mes1 second fortnight8
persona2tipo2mes2first fortnight4
persona2tipo2mes2second fortnight3
persona2tipo2mes3first fortnight8
persona2tipo2mes3second fortnight25
persona3tipo1mes1 first fortnight1
persona3tipo1mes1 second fortnight2
persona3tipo1mes2first fortnight3
persona3tipo1mes2second fortnight4
persona3tipo1mes3first fortnight5
persona3tipo1mes3second fortnight6
persona3tipo2mes1first fortnight5
persona3tipo2mes1 second fortnight8
persona3tipo2mes2first fortnight4
persona3tipo2mes2second fortnight3
persona3tipo2mes3first fortnight8
persona3tipo2mes3second fortnight25

I hope I have explained myself.

Thank you very much in advance

  • Syndicate_Admin 
    Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyivNyVHSgVG5qcWGKJQRCmUMo2J10HWmZRYVlyik5ReV5GWmZ5QARYpTk/PzUlCEqKUIZH1BalFxfp4CyJ0lmQX5IBqEQS4FOdMEiE2B2AxJcSJMsRFU0gKq0BjKNjJFNtqIFKONSDLamBSjjYkwOhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t]),
        #"Transposed Table" = Table.Transpose(Source),
        #"Merged Columns" = Table.CombineColumns(#"Transposed Table",{"Column1", "Column2"},Combiner.CombineTextByDelimiter("|", QuoteStyle.None),"Merged"),
        #"Transposed Table1" = Table.Transpose(#"Merged Columns"),
        #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table1", [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"null|null", type text}, {"null|null_1", type text}, {"mes1|first fortnight", Int64.Type}, {"mes1|second fortnight", Int64.Type}, {"mes2|first fortnight", Int64.Type}, {"mes2|second fortnight", Int64.Type}, {"mes3|first fortnight", Int64.Type}, {"mes3|second fortnight", Int64.Type}}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"null|null", "null|null_1"}, "Attribute", "Value"),
        #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", type text}}),
        #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"null|null", "Person"}, {"null|null_1", "Guy"}, {"Attribute.1", "My"}, {"Attribute.2", "Fortnight"}})
    in
        #"Renamed Columns"


    Watch my video on this topic : https://www.youtube.com/watch?v=_YjFGsS9lNY&t=0s

     



2 Replies

  • Syndicate_Admin 
    Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyivNyVHSgVG5qcWGKJQRCmUMo2J10HWmZRYVlyik5ReV5GWmZ5QARYpTk/PzUlCEqKUIZH1BalFxfp4CyJ0lmQX5IBqEQS4FOdMEiE2B2AxJcSJMsRFU0gKq0BjKNjJFNtqIFKONSDLamBSjjYkwOhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t]),
        #"Transposed Table" = Table.Transpose(Source),
        #"Merged Columns" = Table.CombineColumns(#"Transposed Table",{"Column1", "Column2"},Combiner.CombineTextByDelimiter("|", QuoteStyle.None),"Merged"),
        #"Transposed Table1" = Table.Transpose(#"Merged Columns"),
        #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table1", [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"null|null", type text}, {"null|null_1", type text}, {"mes1|first fortnight", Int64.Type}, {"mes1|second fortnight", Int64.Type}, {"mes2|first fortnight", Int64.Type}, {"mes2|second fortnight", Int64.Type}, {"mes3|first fortnight", Int64.Type}, {"mes3|second fortnight", Int64.Type}}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"null|null", "null|null_1"}, "Attribute", "Value"),
        #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", type text}}),
        #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"null|null", "Person"}, {"null|null_1", "Guy"}, {"Attribute.1", "My"}, {"Attribute.2", "Fortnight"}})
    in
        #"Renamed Columns"


    Watch my video on this topic : https://www.youtube.com/watch?v=_YjFGsS9lNY&t=0s