Forum Discussion

Bristix22's avatar
Bristix22
Frequent Visitor
2 years ago
Solved

Attribute Index issue

Hi, this is a follow up post on my last post here. I thought it was solved; however, another issue came up.    I am trying to take a table where the first 7 columns have static data and then the fo...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Bristix22 ,

     

    I suggest you to try code as below to transform your data in Power Query Editor.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8srPyFNwyU9V0lHKSslPdUjPTczM0UvOzwUKhKQWlyiEpCbmKhgCeUaqQMKxuDi1pETBUAEsDZQxAjKMQTIgEaVYnWilYKBocG5mSQZQoLgYxMBhqIkCTC/UVCMUaRDPyAAhDbPRLzE3VcFYKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Name(static)" = _t, #"Email (static)" = _t, #"Team Name 1" = _t, #"Proj 1 Allocation" = _t, #"Proj 1 Assett" = _t, #"Team Name 2" = _t, #"Proj 2 Allocation" = _t, #"Proj 2 Assett" = _t, #"Team Name 3" = _t]),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Name(static)", "Email (static)"}, "Attribute", "Value"),
        #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "ColumnName", each if Text.Contains([Attribute], "Team Name") then "Team Name" else if Text.Contains([Attribute], "Assett") then "Proj Assett" else if Text.Contains([Attribute], "Allocation") then "Proj Allocation" else ""),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Attribute"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Name(static)", "Email (static)", "ColumnName", "Value"}),
        #"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"Name(static)", Order.Ascending}, {"Email (static)", Order.Ascending}, {"ColumnName", Order.Ascending}}),
        #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Name(static)", "Email (static)", "ColumnName"}, {{"Rows", each _, type table [#"Name(static)"=nullable text, #"Email (static)"=nullable text, ColumnName=text, Value=text]}}),
        #"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Rows],"Index",1)),
        #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom1", "Custom", {"Value", "Index"}, {"Value", "Index"}),
        #"Removed Columns1" = Table.RemoveColumns(#"Expanded Custom",{"Rows"}),
        #"Reordered Columns1" = Table.ReorderColumns(#"Removed Columns1",{"Name(static)", "Email (static)", "Index", "ColumnName", "Value"}),
        #"Changed Type" = Table.TransformColumnTypes(#"Reordered Columns1",{{"Index", Int64.Type}}),
        #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[ColumnName]), "ColumnName", "Value"),
        #"Reordered Columns2" = Table.ReorderColumns(#"Pivoted Column",{"Name(static)", "Email (static)", "Team Name", "Index", "Proj Allocation", "Proj Assett"}),
        #"Removed Columns2" = Table.RemoveColumns(#"Reordered Columns2",{"Index"}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns2",{{"Proj Allocation", Percentage.Type}, {"Proj Assett", type text}, {"Team Name", type text}})
    in
        #"Changed Type1"

    Sample:

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.