Forum Discussion
Anonymous
2 years agoNot applicable
Transpose with Multiple Columns and Rows
Hello, I have a table as below that needs tranformation in power query. This tabels have multiple fields spread across multiple rows and columns for a certain customers that need to be in a separ...
- 2 years ago
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rZHbaoQwEIZfZfB6wZ6u9m4apyqYRJIIK8ve7KHPsI/fiVWzoZZSTQLCDMmXf/yOx+zJr+dsl+H5wt8PPIDSAHu48+KGMFTUDoYOl65vCWAuLTZkJSqYesOt0+4Ht9XWCV2QP+IxZKSdrnBdGt21DzUawpwPmdxQ6Zs57yWu0MqhcCFvU8sh7hyG3za1oPFxLmtVdNaZfs68xIVpOHB42HNR1FboTo0vcePdoBIVwMPov4GwJJDkquI7gC9FL5oxj3XoSJJyf+VpK63I2xlHu499Q5JnIrMw0IsPerkmFxu4acUGblqxgbtRbAxaLTbGrBD76n/R9ZZcbOCmFRu4acUG7kaxMWi12BizQuybT377TC42cNOKDdy0YgN3o9gYtFpsjPmH2NMX", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Customer Number" = _t, #"Customer Name" = _t, Column1.2 = _t, Column1.3 = _t, Column1.4 = _t, Column1.5 = _t]), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Customer Number", "Customer Name"}, "Attribute", "Value"), #"Removed Other Columns" = Table.SelectColumns(#"Unpivoted Other Columns",{"Customer Number", "Customer Name", "Value"}), #"Split Column by Delimiter" = Table.SplitColumn(#"Removed Other Columns", "Value", Splitter.SplitTextByEachDelimiter({":"}, QuoteStyle.Csv, false), {"Column", "Value"}), #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Customer Number", Int64.Type}, {"Customer Name", type text}, {"Column", type text}, {"Value", type text}}), #"Trimmed Text" = Table.TransformColumns(#"Changed Type",{{"Column", Text.Trim, type text},{"Value", Text.Trim, type text}}), #"Filtered Rows" = Table.SelectRows(#"Trimmed Text", each ([Value] <> null and [Value] <> "")), #"Pivoted Column" = Table.Pivot(#"Filtered Rows", List.Distinct(#"Filtered Rows"[Column]), "Column", "Value") in #"Pivoted Column"How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.
- 2 years ago
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rZHbaoQwEIZfZfB6wZ6u9m4apyqYRJIIK8ve7KHPsI/fiVWzoZZSTQLCDMmXf/yOx+zJr+dsl+H5wt8PPIDSAHu48+KGMFTUDoYOl65vCWAuLTZkJSqYesOt0+4Ht9XWCV2QP+IxZKSdrnBdGt21DzUawpwPmdxQ6Zs57yWu0MqhcCFvU8sh7hyG3za1oPFxLmtVdNaZfs68xIVpOHB42HNR1FboTo0vcePdoBIVwMPov4GwJJDkquI7gC9FL5oxj3XoSJJyf+VpK63I2xlHu499Q5JnIrMw0IsPerkmFxu4acUGblqxgbtRbAxaLTbGrBD76n/R9ZZcbOCmFRu4acUG7kaxMWi12BizQuybT377TC42cNOKDdy0YgN3o9gYtFpsjPmH2NMX", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Customer Number" = _t, #"Customer Name" = _t, Column1.2 = _t, Column1.3 = _t, Column1.4 = _t, Column1.5 = _t]), Custom1 = Table.Combine(Table.Group(Source,{"Customer Number","Customer Name"},{"n",each Table.PromoteHeaders(Table.Transpose(Table.FromRows({{"Customer Number",[Customer Number]{0}},{"Customer Name",[Customer Name]{0}}}&List.TransformMany(List.Skip(Table.ToColumns(_),2),each List.Transform(List.RemoveItems(_,{" "}),each Text.Split(Text.Trim(_),":")),(x,y)=>y))))})[n]) in Custom1
wdx223_Daniel
Community Champion
2 years agolet
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rZHbaoQwEIZfZfB6wZ6u9m4apyqYRJIIK8ve7KHPsI/fiVWzoZZSTQLCDMmXf/yOx+zJr+dsl+H5wt8PPIDSAHu48+KGMFTUDoYOl65vCWAuLTZkJSqYesOt0+4Ht9XWCV2QP+IxZKSdrnBdGt21DzUawpwPmdxQ6Zs57yWu0MqhcCFvU8sh7hyG3za1oPFxLmtVdNaZfs68xIVpOHB42HNR1FboTo0vcePdoBIVwMPov4GwJJDkquI7gC9FL5oxj3XoSJJyf+VpK63I2xlHu499Q5JnIrMw0IsPerkmFxu4acUGblqxgbtRbAxaLTbGrBD76n/R9ZZcbOCmFRu4acUG7kaxMWi12BizQuybT377TC42cNOKDdy0YgN3o9gYtFpsjPmH2NMX", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Customer Number" = _t, #"Customer Name" = _t, Column1.2 = _t, Column1.3 = _t, Column1.4 = _t, Column1.5 = _t]),
Custom1 = Table.Combine(Table.Group(Source,{"Customer Number","Customer Name"},{"n",each Table.PromoteHeaders(Table.Transpose(Table.FromRows({{"Customer Number",[Customer Number]{0}},{"Customer Name",[Customer Name]{0}}}&List.TransformMany(List.Skip(Table.ToColumns(_),2),each List.Transform(List.RemoveItems(_,{" "}),each Text.Split(Text.Trim(_),":")),(x,y)=>y))))})[n])
in
Custom1