Forum Discussion

Lara137's avatar
Lara137
New Member
2 years ago
Solved

Power BI : data transformation with Power query

Hello everyone!

 

I'm new in Power BI and should to transform data in Power query for convinient analizing.

I need to have one column for date (years), one column for Units and one column for sales, EUR. 

I tried to Unpivot columns, but didn't get the needed result.

 

Could you please advise some aproach? 

 

Thank you in advance!

 

Here is the part od data.

 

Sku name    Quarter       2019, Units          2019, EUR              2020, Units            2020, EUR

5_SKU            Q1                 253                   825                           0                        0

5_SKU            Q2                 125                    569                          0                         0

5_SKU            Q3                   89                    425                          0                         0

5_SKU            Q4                    98                    657                         0                          0

5_SKU            Q1                    0                        0                         124                     985

5_SKU            Q2                     0                       0                          98                      741

5_SKU            Q3                     0                      0                           74                      695

5_SKU            Q4                     0                      0                           97                      954

  • let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dY4xDoAgDEXv0pnBYgv0DE7GOBHi/W9hWwMxQQfeQF9/f63A17GdEGBHReRVWSIrF38tvJSoQB9ykm/F921GfyGkkKJInL8NHN927vF5btIVD8uEc5FuZMtIwnORkWFVhAlauwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Sku name" = _t, Quarter = _t, #"2019, Units" = _t, #"2019, EUR" = _t, #"2020, Units" = _t, #"2020, EUR" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Sku name", type text}, {"Quarter", type text}, {"2019, Units", Int64.Type}, {"2019, EUR", Int64.Type}, {"2020, Units", Int64.Type}, {"2020, EUR", Int64.Type}}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Sku name", "Quarter"}, "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", Int64.Type}, {"Attribute.2", type text}}),
        #"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[Attribute.2]), "Attribute.2", "Value", List.Sum)
    in
        #"Pivoted Column"

     

    Copy and paste the full example into your advanced editor.

1 Reply

  • let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dY4xDoAgDEXv0pnBYgv0DE7GOBHi/W9hWwMxQQfeQF9/f63A17GdEGBHReRVWSIrF38tvJSoQB9ykm/F921GfyGkkKJInL8NHN927vF5btIVD8uEc5FuZMtIwnORkWFVhAlauwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Sku name" = _t, Quarter = _t, #"2019, Units" = _t, #"2019, EUR" = _t, #"2020, Units" = _t, #"2020, EUR" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Sku name", type text}, {"Quarter", type text}, {"2019, Units", Int64.Type}, {"2019, EUR", Int64.Type}, {"2020, Units", Int64.Type}, {"2020, EUR", Int64.Type}}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Sku name", "Quarter"}, "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", Int64.Type}, {"Attribute.2", type text}}),
        #"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[Attribute.2]), "Attribute.2", "Value", List.Sum)
    in
        #"Pivoted Column"

     

    Copy and paste the full example into your advanced editor.