Forum Discussion

GCH_Ryan's avatar
GCH_Ryan
Frequent Visitor
6 years ago
Solved

Transpose Columns for Gantt 2.2.3

I have a table that is currently set-up like this:    Project Project Manager Task 1 Start Task 1 End Task 2 Start  Milestone 1 Milestone 2 Task 2 End Task 3 Start Milestone 3 Task 3 E...
  • camargos88's avatar
    6 years ago

    Hi GCH_Ryan 

    Try this code on Advanced Editor (I assumed you are using TAB as separator):

    let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKz0pNLlHSgbEUfBPzEtNTi4AiIYnF2QqGCsEliUUlCK5rXgqMYwSRUwDyfTNzUotL8vNSFQxReEYItUgajeGGIlQaIyRBKmN14I4DGxngC6aM9Q31jQyMDMBMUwTTDME0RzAtEUxDAyQ2khmGSIYYQdUg220EsRtEKRDEyBqNFcA6DQnrQtdpArESFCA4UWwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t, Column9 = _t, Column10 = _t, Column11 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text}, {"Column9", type text}, {"Column10", type text}, {"Column11", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Project", type text}, {"Project Manager", type text}, {"Task 1 Start", type date}, {"Task 1 End", type date}, {"Task 2 Start ", type date}, {"Milestone 1", type date}, {"Milestone 2", type date}, {"Task 2 End", type date}, {"Task 3 Start", type date}, {"Milestone 3", type text}, {"Task 3 End", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"Project", "Project Manager"}, "Attribute", "Value"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Columns", "Label", each if Text.Contains([Attribute], "Start") then "Start"
    else if Text.Contains([Attribute], "End") then "End" else "Milestone"),
    #"Pivoted Column" = Table.Pivot(#"Added Custom", List.Distinct(#"Added Custom"[Label]), "Label", "Value"),
    #"Replaced Value" = Table.ReplaceValue(#"Pivoted Column","Start","",Replacer.ReplaceText,{"Attribute"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","End","",Replacer.ReplaceText,{"Attribute"}),
    #"Trimmed Text" = Table.TransformColumns(#"Replaced Value1",{{"Project", Text.Trim, type text}, {"Project Manager", Text.Trim, type text}, {"Attribute", Text.Trim, type text}}),
    #"Cleaned Text" = Table.TransformColumns(#"Trimmed Text",{{"Project", Text.Clean, type text}, {"Project Manager", Text.Clean, type text}, {"Attribute", Text.Clean, type text}}),
    #"Grouped Rows" = Table.Group(#"Cleaned Text", {"Project", "Project Manager", "Attribute"}, {{"Start", each List.Max([Start]), type date}, {"End", each List.Max([End]), type anynonnull}, {"Milestone", each List.Max([Milestone]), type anynonnull}}),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Grouped Rows", {{"Start", type date}, {"End", type date}, {"Milestone", type date}}, "en-US")
    in
    #"Changed Type with Locale"

     

     

    I hope it can help you,

     

    Ricardo