let
Source1 = Excel.CurrentWorkbook(){[Name="tblprofit"]}[Content],
#"Filtered Rows1" = Table.SelectRows(Source1, each ([Sales organisation] <> null) and ([Import] = "X")),
#"Changed Type1" = Table.TransformColumnTypes(#"Filtered Rows1",{{"Remove pastille on forecast", type date}}),
#"Removed Duplicates" = Table.Distinct(#"Changed Type1", {"Sales organisation", "Main Division", "Sales Org Currency"}),
#"Renamed Columns2" = Table.RenameColumns(#"Removed Duplicates",{{"Main Division", "Division"}}),
#"Removed Other Columns" = Table.SelectColumns(#"Renamed Columns2",{"Sales organisation", "Division"}),
#"Added Custom" = Table.AddColumn(#"Removed Other Columns", "Report Group", each "GRP01"),
#"Added Custom4" = Table.AddColumn(#"Added Custom", "Unit", each "TO"),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Added Custom4", {"Division", "Report Group", "Unit"}, "Attribute", "Value"),
#"Unpivoted Columns1" = Table.UnpivotOtherColumns(#"Unpivoted Columns", {"Report Group", "Unit", "Attribute", "Value"}, "Attribute.1", "Value.1"),
Custom6 = Table.InsertRows(#"Unpivoted Columns1", 0, {[Report Group = #"Unpivoted Columns1"{0}[Report Group], Unit = #"Unpivoted Columns1"{0}[Unit], Attribute = #"Unpivoted Columns1"{0}[Attribute],Value = "-----",Attribute.1 = #"Unpivoted Columns1"{0}[Attribute.1],Value.1 = "-----"],[Report Group = #"Unpivoted Columns1"{0}[Report Group], Unit = #"Unpivoted Columns1"{0}[Unit], Attribute = #"Unpivoted Columns1"{0}[Attribute],Value = "*",Attribute.1 = #"Unpivoted Columns1"{0}[Attribute.1],Value.1 = "*"],[Report Group = #"Unpivoted Columns1"{0}[Report Group], Unit = #"Unpivoted Columns1"{0}[Unit], Attribute = #"Unpivoted Columns1"{0}[Attribute],Value = "-----",Attribute.1 = #"Unpivoted Columns1"{0}[Attribute.1],Value.1 = "-----"]}),
#"Cleaned Sales Org" = Custom6,
Source2 = Excel.CurrentWorkbook(){[Name="CG_SIOP"]}[Content],
#"Filtered Rows2" = Table.SelectRows(Source2, each ([SIOP Customer Groups] <> null)),
#"Added Custom1" = Table.AddColumn(#"Filtered Rows2", "Report Group", each "GRP02"),
#"Added Custom5" = Table.AddColumn(#"Added Custom1", "Unit", each "TO"),
#"Renamed Columns1" = Table.RenameColumns(#"Added Custom5",{{"SIOP Customer Groups", "SIOP Customer Group"}}),
#"Unpivoted Columns2" = Table.UnpivotOtherColumns(#"Renamed Columns1", {"Report Group", "Unit"}, "Attribute", "Value"),
Custom5 = Table.InsertRows(#"Unpivoted Columns2", 0, {[Report Group = #"Unpivoted Columns2"{0}[Report Group], Unit = #"Unpivoted Columns2"{0}[Unit], Attribute = #"Unpivoted Columns2"{0}[Attribute],Value = "-----"],[Report Group = #"Unpivoted Columns2"{0}[Report Group], Unit = #"Unpivoted Columns2"{0}[Unit], Attribute = #"Unpivoted Columns2"{0}[Attribute],Value = "*"],[Report Group = #"Unpivoted Columns2"{0}[Report Group], Unit = #"Unpivoted Columns2"{0}[Unit], Attribute = #"Unpivoted Columns2"{0}[Attribute],Value = "-----"]}),
#"Cleaned CG" = Custom5,
Source3 = Excel.CurrentWorkbook(){[Name="SIOPMatGroup"]}[Content],
#"Filtered Rows3" = Table.SelectRows(Source3, each ([SIOP MatGroup] <> null)),
#"Added Custom2" = Table.AddColumn(#"Filtered Rows3", "Report Group", each "GR03"),
#"Added Custom6" = Table.AddColumn(#"Added Custom2", "Unit", each "TO"),
#"Unpivoted Columns3" = Table.UnpivotOtherColumns(#"Added Custom6", {"Report Group", "Unit"}, "Attribute", "Value"),
Custom1 = Table.InsertRows(#"Unpivoted Columns3", 0, {[Report Group = #"Unpivoted Columns3"{0}[Report Group], Unit = #"Unpivoted Columns3"{0}[Unit], Attribute = #"Unpivoted Columns3"{0}[Attribute],Value = "-----"]}),
#"Cleaned MG" = Custom1,
Source4 = Excel.CurrentWorkbook(){[Name="Focus_list"]}[Content],
#"Removed Other Columns1" = Table.SelectColumns(Source4,{"Key Focus"}),
#"Removed Duplicates1" = Table.Distinct(#"Removed Other Columns1"),
#"Filtered Rows4" = Table.SelectRows(#"Removed Duplicates1", each [Key Focus] <> null),
#"Added Custom3" = Table.AddColumn(#"Filtered Rows4", "Report Group", each "GR04"),
#"Added Custom7" = Table.AddColumn(#"Added Custom3", "Unit", each "QTY"),
#"Unpivoted Columns4" = Table.UnpivotOtherColumns(#"Added Custom7", {"Report Group", "Unit"}, "Attribute", "Value"),
Custom2 = Table.InsertRows(#"Unpivoted Columns4", 0, {[Report Group = #"Unpivoted Columns4"{0}[Report Group], Unit = #"Unpivoted Columns4"{0}[Unit], Attribute = #"Unpivoted Columns4"{0}[Attribute],Value = "-----"]}),
#"Cleaned Focus" = Custom2,
#"Appended Query" = Table.Combine({#"Cleaned Sales Org", #"Cleaned CG", #"Cleaned MG", #"Cleaned Focus"}),
#"Reordered Columns" = Table.ReorderColumns(#"Appended Query",{"Report Group", "Attribute.1", "Value.1", "Attribute", "Value", "Unit"}),
#"Replaced Value3" = Table.ReplaceValue(#"Reordered Columns","","",Replacer.ReplaceValue,{"Attribute.1"}),
#"Replaced Value4" = Table.ReplaceValue(#"Replaced Value3",null,each [Attribute],Replacer.ReplaceValue,{"Attribute.1"}),
Custom4 = Table.ReplaceValue(#"Replaced Value4",null,each [Value],Replacer.ReplaceValue,{"Value.1"}),
Final = Custom4
in
Final