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: null null mes1 mes1 mes2 mes2 mes3 mes3 null null first fortnight second fortnight fir...
  • Fowmy's avatar
    5 years ago

    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