Forum Discussion
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:
| Name | Type | L Value | R Value |
| a | L | 10 | |
| b | R | 25 | |
| c | Both | 15 | 30 |
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?
| Name | Type | Value |
| a | L | 10 |
| b | R | 25 |
| c | Both | 15 |
| c | Both | 30 |
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 HafizLaveigo1
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
- shafiz_pSuper User
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 - sanalyticsSuper User
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
- Omid_MotamediseSuper User
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"