Forum Discussion

BI-Beginner's avatar
BI-Beginner
New Member
3 years ago
Solved

Table transformation challenge

Hi, I am somewhat new to PowerBI. Only been using it for less than a year. I have a dataset in the format below (top). What is the best way to transform it to the format on the bottom? Appreciate all...
  • v-yalanwu-msft's avatar
    3 years ago

    Hi, BI-Beginner ;

    As HotChilli said, I'll add specific steps:

    1.unpivot columns.

    2.split column by "#".

    3.select two columns then pivot it.

    4.delete Attribute.2 column and the final result:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjQ0MlbSUSpPSQSSKqYgZlERiGmmFKsTreRiYmYO5CWmpIHEQCpTU1NBTAul2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t, #"Supplier Name#1" = _t, #" Supplier Cost#1" = _t, #"Supplier Name#2" = _t, #" Supplier Cost#2" = _t]),
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"Item"}, "Attribute", "Value"),
        #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Columns", "Attribute", Splitter.SplitTextByDelimiter("#", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
        #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Item", type text}, {"Attribute.1", type text}, {"Attribute.2", Int64.Type}}),
        #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Attribute.1]), "Attribute.1", "Value"),
        #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Attribute.2"})
    in
        #"Removed Columns"


    Best Regards,
    Community Support Team _ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.