Hi ,
My solution for this workout:
let
Source = Excel.Workbook(File.Contents("E:\WorkOut\PowerQuery\2 Extract Customers with max Sales.xlsx"), null, true),
Data_Table = Source{[Item="Data",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(Data_Table,{{"Location", type text}, {"Customer", type text}, {"Customer Nr.", type text}, {"cw01", Int64.Type}, {"cw02", Int64.Type}, {"cw03", Int64.Type}, {"cw04", Int64.Type}, {"cw05", Int64.Type}, {"cw06", Int64.Type}, {"cw07", Int64.Type}, {"cw08", Int64.Type}, {"cw09", Int64.Type}, {"cw10", Int64.Type}, {"cw11", Int64.Type}, {"cw12", Int64.Type}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Location", "Customer", "Customer Nr."}, "Attribute", "Value"),
#"Renamed Columns" = Table.RenameColumns(#"Unpivoted Other Columns",{{"Attribute", "CW"}}),
#"Grouped Rows" = Table.Group(#"Renamed Columns", {"Location", "CW"}, {{"Count", each _, type table [Location=nullable text, Customer=nullable text, #"Customer Nr."=nullable text, CW=text, Value=number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "maxsale", each let
a= Table.Max([Count],"Value")
in
a),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"maxsale"}),
#"Expanded maxsale" = Table.ExpandRecordColumn(#"Removed Other Columns", "maxsale", {"Location", "Customer", "CW"}, {"Location", "Customer", "CW"}),
#"Pivoted Column" = Table.Pivot(#"Expanded maxsale", List.Distinct(#"Expanded maxsale"[Location]), "Location", "Customer"),
#"Changed Type1" = Table.TransformColumnTypes(#"Pivoted Column",{{"CW", type text}, {"NY", type text}, {"TKY", type text}})
in
#"Changed Type1"
PowerQuery2.pbix (24.6 KB)
Thanks