Forum Discussion
Combining data from two columns with different dates
- Anonymous2 years ago
Hi Cenex_Chris ,
Your Month1 and Month2 are distributed in two columns, which is inconvenient when you create visual objects. Since this is the Power Query forum, I suggest you use the following M code in Power Query to transform your data:let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgtKs7PU3BU0lEKKMrPSk0uUTAEsr0S83SNTIAMQ1Mg4ZaaBOGZKsXqYNVjhKzHGFmLAS4tKKoMDYCEb2IRlIesxwmnNQY47XFG8w5clZEhsj3muPQYI9uDEgJGuLSYoHgH2RZjpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Person = _t, Project = _t, #"Month 1" = _t, #"Month 1 Hours" = _t, #"Month 2" = _t, #"Month 2 hours" = _t]), #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Month 1", type date}, {"Month 2", type date}}, "en-GB"), #"Changed Type" = Table.TransformColumnTypes(#"Changed Type with Locale",{{"Month 1 Hours", Int64.Type}, {"Month 2 hours", Int64.Type}}), #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Changed Type", {{"Month 1", type text}, {"Month 1 Hours", type text}}, "en-US"),{"Month 1", "Month 1 Hours"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"), #"Merged Columns1" = Table.CombineColumns(Table.TransformColumnTypes(#"Merged Columns", {{"Month 2", type text}, {"Month 2 hours", type text}}, "en-US"),{"Month 2", "Month 2 hours"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged.1"), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Merged Columns1", {"Person", "Project"}, "Attribute", "Value"), #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Value", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Value.1", "Value.2"}), #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Value.1", type date}, {"Value.2", Int64.Type}}), #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Attribute"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Value.1", "Month"}, {"Value.2", "Value"}}) in #"Renamed Columns"Just create a blank query and put all of the function into the Advanced Editor:
And after transformation:
Then click "Close and Apply":
Then you can create the visual, here I will give you an example:
Or like this:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Cenex_Chris ,
Your Month1 and Month2 are distributed in two columns, which is inconvenient when you create visual objects. Since this is the Power Query forum, I suggest you use the following M code in Power Query to transform your data:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkgtKs7PU3BU0lEKKMrPSk0uUTAEsr0S83SNTIAMQ1Mg4ZaaBOGZKsXqYNVjhKzHGFmLAS4tKKoMDYCEb2IRlIesxwmnNQY47XFG8w5clZEhsj3muPQYI9uDEgJGuLSYoHgH2RZjpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Person = _t, Project = _t, #"Month 1" = _t, #"Month 1 Hours" = _t, #"Month 2" = _t, #"Month 2 hours" = _t]),
#"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Month 1", type date}, {"Month 2", type date}}, "en-GB"),
#"Changed Type" = Table.TransformColumnTypes(#"Changed Type with Locale",{{"Month 1 Hours", Int64.Type}, {"Month 2 hours", Int64.Type}}),
#"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Changed Type", {{"Month 1", type text}, {"Month 1 Hours", type text}}, "en-US"),{"Month 1", "Month 1 Hours"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
#"Merged Columns1" = Table.CombineColumns(Table.TransformColumnTypes(#"Merged Columns", {{"Month 2", type text}, {"Month 2 hours", type text}}, "en-US"),{"Month 2", "Month 2 hours"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged.1"),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Merged Columns1", {"Person", "Project"}, "Attribute", "Value"),
#"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Value", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Value.1", "Value.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Value.1", type date}, {"Value.2", Int64.Type}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Attribute"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Value.1", "Month"}, {"Value.2", "Value"}})
in
#"Renamed Columns"
Just create a blank query and put all of the function into the Advanced Editor:
And after transformation:
Then click "Close and Apply":
Then you can create the visual, here I will give you an example:
Or like this:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.