Forum Discussion
Lefuneste57
2 years agoHelper I
Rotate column
Hi, i have a table like this :
And i will have a table like this result :
I need this result to make a Gant graph and to do this, i must have only two column. One with Start date and another one with End Date. I have try in Power query with rotate column function but it does not work.
I hope you can find a solution for my probleme.
Thanks in advance.
Lefuneste57 You need to use Power Query for this:
Create a new query and paste this code in the advanced editor:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY+9DoMwDIRfBTFX8k8SIGO7dO+KGFBAVSQaKghD375xIUzd7rNPd3bblldiU5WX8rb5wYdn4Xz8JCQgYGSVpAHCrJOic8EEaAR0AoX/obukDja6TuPH3A+Fm8Mal81FPwdJbABZrCRAoLPmnEFH7+liUCJZ5vY4jvci2/yeuU/9uhbL+J56N77GENOshioZqZEAc3whaRYkmKykGUCVgStAfW40oN2h674=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Project = _t, #"Project Name" = _t, #"Start Date Call For Tender" = _t, #"End Date Call For Tender" = _t, #"Start Date Works" = _t, #"End Date Works" = _t, #"Start Date Finishing" = _t, #"End Date Finishing" = _t]), ChangedType = Table.TransformColumnTypes(Source,{{"Project", type text}, {"Project Name", type text}, {"Start Date Call For Tender", type text}, {"End Date Call For Tender", type text}, {"Start Date Works", type text}, {"End Date Works", type text}, {"Start Date Finishing", type text}, {"End Date Finishing", type text}}), ConvertToDate = Table.TransformColumnTypes(ChangedType, {{"End Date Call For Tender", type date}, {"Start Date Call For Tender", type date}, {"Start Date Works", type date}, {"End Date Works", type date}, {"Start Date Finishing", type date}, {"End Date Finishing", type date}}, "en-GB"), Unipvot = Table.UnpivotOtherColumns ( ConvertToDate, { "Project", "Project Name" }, "Name", "Date" ), Group = Table.Group ( Unipvot, { "Project", "Project Name" }, { { "Count", each let CurrentGroup = _, GetStartDate = Table.AddColumn ( CurrentGroup, "Start Date", each if Text.StartsWith ( [Name], "Start Date" ) = true then [Date] else null ), GetEndDate = Table.AddColumn ( GetStartDate, "End Date", each if Text.StartsWith ( [Name], "End Date" ) = true then [Date] else null ), FillDown = Table.FillDown ( GetEndDate, { "Start Date" } ), RemoveNulls = Table.SelectRows ( FillDown, each [End Date] <> null ) in RemoveNulls, type table [ Name = text, Start Date = date, End Date = date ] } } ), Expand = Table.ExpandTableColumn ( Group, "Count", { "Name", "Start Date", "End Date" }, { "Name", "Start Date", "End Date" } ), Replace = Table.ReplaceValue ( Expand, "End Date ", "", Replacer.ReplaceText, { "Name" } ) in Replace
2 Replies
- AntrikshSharmaCommunity Champion
Lefuneste57 You need to use Power Query for this:
Create a new query and paste this code in the advanced editor:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY+9DoMwDIRfBTFX8k8SIGO7dO+KGFBAVSQaKghD375xIUzd7rNPd3bblldiU5WX8rb5wYdn4Xz8JCQgYGSVpAHCrJOic8EEaAR0AoX/obukDja6TuPH3A+Fm8Mal81FPwdJbABZrCRAoLPmnEFH7+liUCJZ5vY4jvci2/yeuU/9uhbL+J56N77GENOshioZqZEAc3whaRYkmKykGUCVgStAfW40oN2h674=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Project = _t, #"Project Name" = _t, #"Start Date Call For Tender" = _t, #"End Date Call For Tender" = _t, #"Start Date Works" = _t, #"End Date Works" = _t, #"Start Date Finishing" = _t, #"End Date Finishing" = _t]), ChangedType = Table.TransformColumnTypes(Source,{{"Project", type text}, {"Project Name", type text}, {"Start Date Call For Tender", type text}, {"End Date Call For Tender", type text}, {"Start Date Works", type text}, {"End Date Works", type text}, {"Start Date Finishing", type text}, {"End Date Finishing", type text}}), ConvertToDate = Table.TransformColumnTypes(ChangedType, {{"End Date Call For Tender", type date}, {"Start Date Call For Tender", type date}, {"Start Date Works", type date}, {"End Date Works", type date}, {"Start Date Finishing", type date}, {"End Date Finishing", type date}}, "en-GB"), Unipvot = Table.UnpivotOtherColumns ( ConvertToDate, { "Project", "Project Name" }, "Name", "Date" ), Group = Table.Group ( Unipvot, { "Project", "Project Name" }, { { "Count", each let CurrentGroup = _, GetStartDate = Table.AddColumn ( CurrentGroup, "Start Date", each if Text.StartsWith ( [Name], "Start Date" ) = true then [Date] else null ), GetEndDate = Table.AddColumn ( GetStartDate, "End Date", each if Text.StartsWith ( [Name], "End Date" ) = true then [Date] else null ), FillDown = Table.FillDown ( GetEndDate, { "Start Date" } ), RemoveNulls = Table.SelectRows ( FillDown, each [End Date] <> null ) in RemoveNulls, type table [ Name = text, Start Date = date, End Date = date ] } } ), Expand = Table.ExpandTableColumn ( Group, "Count", { "Name", "Start Date", "End Date" }, { "Name", "Start Date", "End Date" } ), Replace = Table.ReplaceValue ( Expand, "End Date ", "", Replacer.ReplaceText, { "Name" } ) in Replace- Lefuneste57Helper IThank you very much, it works, I could never have done it alone. Thank you again for your help. Good day.