Forum Discussion

Laveigo1's avatar
Laveigo1
New Member
1 year ago
Solved

How to combine multiple value columns into one value column but multiple rows for certain condition

Hi

 

I am trying to get my data from the following format:

NameTypeL ValueR Value
aL10 
bR 25
cBoth1530

 

into the following format in Power Query (i.e. if type is "Both" then value from 2 columns are split into 2 rows). I will then use the value column to calculate average of value using a pivot table afterwards. Could you please advise on how to do this?

NameTypeValue
aL10
bR25
cBoth15
cBoth30

 

Thanks in advance for your help!

  • Hi Laveigo1  Seem unpivoting other column will solve your problem. See image:

     

    Select Name and Type, right click and select unpivot other column and you are done. 

    Output:

     

    Delete Attribute column.

    Hope this helps!!

    If this solved your problem, please accept it as a solution and a kudos!!

     

    Best Regards,
    Shahariar Hafiz

  • Laveigo1 
    Simple do the unpivot and you will get your result.

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Type", type text}, {"L Value", Int64.Type}, {"R Value", Int64.Type}}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Name", "Type"}, "Attribute", "Value"),
        #"Removed Other Columns" = Table.SelectColumns(#"Unpivoted Other Columns",{"Name", "Type", "Value"})
    in
        #"Removed Other Columns"

     

    Regards

    sanalytics



  • Hi Laveigo1 

    just copy the below code and past it into the advance editor

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUfIBYkMDIKGgFKsTrZQEZAWBeTpKRqZgoWQg0ym/JAOk0BRIGBsoxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Type = _t, #"L Value" = _t, #"R Value" = _t]),
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"Name", "Type"}, "Attribute", "Value"),
        #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each ([Value] <> " "))
    in
        #"Filtered Rows"

3 Replies

  • Hi Laveigo1  Seem unpivoting other column will solve your problem. See image:

     

    Select Name and Type, right click and select unpivot other column and you are done. 

    Output:

     

    Delete Attribute column.

    Hope this helps!!

    If this solved your problem, please accept it as a solution and a kudos!!

     

    Best Regards,
    Shahariar Hafiz

  • Laveigo1 
    Simple do the unpivot and you will get your result.

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Type", type text}, {"L Value", Int64.Type}, {"R Value", Int64.Type}}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Name", "Type"}, "Attribute", "Value"),
        #"Removed Other Columns" = Table.SelectColumns(#"Unpivoted Other Columns",{"Name", "Type", "Value"})
    in
        #"Removed Other Columns"

     

    Regards

    sanalytics



  • Hi Laveigo1 

    just copy the below code and past it into the advance editor

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUfIBYkMDIKGgFKsTrZQEZAWBeTpKRqZgoWQg0ym/JAOk0BRIGBsoxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Type = _t, #"L Value" = _t, #"R Value" = _t]),
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"Name", "Type"}, "Attribute", "Value"),
        #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each ([Value] <> " "))
    in
        #"Filtered Rows"