Forum Discussion
Extract single table row/record into multi records
- 5 years ago
Place the following M code in a blank query to see the steps:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkktLjE0MlbSUfJNTc5IzMtMBjLBfEMjpVgdZAUhQAVA+czEPCDHxASkzgJNiWtOanJJUWZyYg5IiQGQsDCFKzExNUO1xhhkhpkZmgIUa4zA1higKUGxBuhOHSVTQ6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project#" = _t, #"Resource Type" = _t, #"Week 1" = _t, #"Week 2" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project#", type text}, {"Resource Type", type text}, {"Week 1", Int64.Type}, {"Week 2", Int64.Type}}), #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Project#", "Resource Type"}, "Week Number", "Hours forecast") in #"Unpivoted Columns"IT is the last step that's important. You just select the weekNumber columns and choose unpivot columns in the GUI, then change column names if necessary
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Place the following M code in a blank query to see the steps:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkktLjE0MlbSUfJNTc5IzMtMBjLBfEMjpVgdZAUhQAVA+czEPCDHxASkzgJNiWtOanJJUWZyYg5IiQGQsDCFKzExNUO1xhhkhpkZmgIUa4zA1higKUGxBuhOHSVTQ6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project#" = _t, #"Resource Type" = _t, #"Week 1" = _t, #"Week 2" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project#", type text}, {"Resource Type", type text}, {"Week 1", Int64.Type}, {"Week 2", Int64.Type}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Project#", "Resource Type"}, "Week Number", "Hours forecast")
in
#"Unpivoted Columns"
IT is the last step that's important. You just select the weekNumber columns and choose unpivot columns in the GUI, then change column names if necessary
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Thanks very much to you both, worked perfectly. 🙂