Forum Discussion

bharatmalvi's avatar
bharatmalvi
Frequent Visitor
4 years ago
Solved

URGENT-Need help for Unpivot in below format

Name Parameter Value x y 12/12/22 x y 12/12/22 x z 23 x z 18   Hello Team, I want the above table in below form, Pls support.   Name       y     z x 12/12/22 ...
  • Vijay_A_Verma's avatar
    Vijay_A_Verma
    4 years ago

    File uploaded to https://1drv.ms/x/s!Akd5y6ruJhvhuhOCASxESIut-dlV?e=Sy6hAw 

    Use below code

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Column1", "Color Name"}, "Attribute", "Value"),
        #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),
        #"Replaced Value" = Table.ReplaceValue(#"Removed Columns","null",null,Replacer.ReplaceValue,{"Value"}),
        #"Grouped Rows" = Table.Group(#"Replaced Value", {"Column1"}, {{"All", each Table.AddIndexColumn(_,"Index",0,1)}}),
        #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Color Name", "Value", "Index"}, {"Color Name", "Value", "Index"}),
        #"Pivoted Column" = Table.Pivot(#"Expanded All", List.Distinct(#"Expanded All"[Column1]), "Column1", "Value"),
        #"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Index"}),
        #"Added Custom" = Table.AddColumn(#"Removed Columns1", "Custom", each [Month]=null and [Foil Solid]=null),
        #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = false)),
        #"Removed Columns2" = Table.RemoveColumns(#"Filtered Rows",{"Custom"})
    in
        #"Removed Columns2"