Automatizando Consolidated So

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 23

ROLLING_FCT_SUMMARY

let

actmonth = if fnGetParameter("ACT_MTH")=null then 0 else Date.Month(Date.AddMonths(Date.FromText("1-"&


fnGetParameter("ACT_MTH")),-3)),

event = "FY"&Text.End(Text.From(fnGetParameter("CUR_FY")),2)&" "&


Text.From(Date.Month( Date.FromText("1-"& fnGetParameter("FCT_MTH")) )) &"F",

Path = fnGetParameter("FCT_PATH"),

UseSrlaFct = (fnGetParameter("SRLAFCT_SRC") = "SRLA"),

Origen = Folder.Files(Path & "\1. Rolling Forecast"),

#"Filtered Rows1" = Table.SelectRows(Origen, each ([Extension] = ".xlsm")),

#"Filtered Rows" = Table.SelectRows(#"Filtered Rows1", each not Text.Contains([Name], "~$")),

#"Otras columnas quitadas" = Table.SelectColumns(#"Filtered Rows",{"Content"}),

#"Personalizada agregada" = Table.AddColumn(#"Otras columnas quitadas", "GetExcelData", each


Excel.Workbook([Content])),

#"Columnas quitadas" = Table.RemoveColumns(#"Personalizada agregada",{"Content"}),

#"Se expandió GetExcelData" = Table.ExpandTableColumn(#"Columnas quitadas", "GetExcelData", {"Name",


"Data"}, {"Name", "Data"}),

#"Filtered Rows5" = Table.SelectRows(#"Se expandió GetExcelData", each ([Name] = "PSIRANGE2")),

#"Personalizada agregada2" = Table.AddColumn(#"Filtered Rows5", "PromoteHeader", each


Table.PromoteHeaders([Data])),

#"Otras columnas quitadas1" = Table.SelectColumns(#"Personalizada agregada2",{"PromoteHeader"}),

#"Expanded PromoteHeader1" = Table.ExpandTableColumn(#"Otras columnas quitadas1", "PromoteHeader",

{"CHANNEL GROUP", "DEALER", "PAYER CODE", "PAYER", "CATEGORY", "SUB CATEGORY", "SKU", "8D CODE",
"MODEL NAME", "SERIES", "EVENT", "ITEM", "JAN -", "FEB -", "MAR -", "APR", "MAY", "JUN", "JUL", "AUG", "SEP",
"OCT", "NOV", "DEC", "JAN", "FEB", "MAR", "APR +", "MAY +", "JUN +"},

{"Channel Group", "Dealer", "Payer Code", "Payer", "Category", "Sub Category", "SKU", "8D Code", "Model
Name", "SERIES", "FY", "ITEM", "JAN FY15", "FEB FY15", "MAR FY15", "APR FY16", "MAY FY16", "JUN FY16", "JUL
FY16", "AUG FY16", "SEP FY16", "OCT FY16", "NOV FY16", "DEC FY16", "JAN FY16", "FEB FY16", "MAR FY16", "APR
FY17", "MAY FY17", "JUN FY17"}),

#"Filtered Rows2" = Table.SelectRows(#"Expanded PromoteHeader1", each ([FY] = event)),

#"Filtered SOLA" = Table.SelectRows(#"Filtered Rows2", each ([Dealer] <> "SOLA")),

#"Replaced Value10" = Table.ReplaceValue(#"Filtered SOLA",null,0,Replacer.ReplaceValue,{"JAN FY15", "FEB


FY15", "MAR FY15", "APR FY16", "MAY FY16", "JUN FY16", "JUL FY16", "AUG FY16", "SEP FY16", "OCT FY16", "NOV
FY16", "DEC FY16", "JAN FY16", "FEB FY16", "MAR FY16", "APR FY17", "MAY FY17", "JUN FY17"}),

#"Removed Columns1" = Table.RemoveColumns(#"Replaced Value10",{"JAN FY15", "FEB FY15", "MAR FY15", "APR
FY17", "MAY FY17", "JUN FY17"}),
#"Unpivoted Other Columns1" = Table.UnpivotOtherColumns(#"Removed Columns1", {"Channel Group", "Dealer",
"Payer Code", "Payer", "Category", "Sub Category", "SKU", "8D Code", "Model Name", "SERIES", "FY", "ITEM"},
"Month", "Value"),

#"Changed Type1" = Table.TransformColumnTypes(#"Unpivoted Other Columns1",{{"Value", type number}}),

#"Filtered Rows7" = Table.SelectRows(#"Changed Type1", each ([ITEM] = "Channel Inv" or [ITEM] = "Ranging" or
[ITEM] = "Sell out AMT" or [ITEM] = "Sell Out QTY")),

#"Replaced Value9" = Table.ReplaceValue(#"Filtered Rows7"," FY16","",Replacer.ReplaceText,{"Month"}),

#"Pivoted Column" = Table.Pivot(#"Replaced Value9", List.Distinct(#"Replaced Value9"[ITEM]), "ITEM", "Value",


List.Sum),

#"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Channel Inv", "Inventory QTY"}, {"Sell out


AMT", "Sell Out AMT"}}),

#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Payer Code", type text}, {"8D Code",


type text}}),

#"Replaced Value" = Table.ReplaceValue(#"Changed Type","#SRLA","80001",Replacer.ReplaceText,{"Payer


Code"}),

#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","#WS","#",Replacer.ReplaceText,{"Payer Code"}),

#"Merged Queries1" = Table.NestedJoin(#"Replaced Value1",{"Payer Code"},DEALER_MASTER,{"Payer


Code"},"NewColumn",JoinKind.LeftOuter),

#"Removed Columns" = Table.RemoveColumns(#"Merged Queries1",{"Channel Group", "Dealer", "Payer Code",


"Payer"}),

#"Expanded NewColumn1" = Table.ExpandTableColumn(#"Removed Columns", "NewColumn", {"Country",


"Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name", "Payer
Code"}, {"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store",
"Payer Name", "Payer Code"}),

RMNULL = Table.ReplaceValue(#"Expanded NewColumn1",null,0,Replacer.ReplaceValue,{"Sell Out QTY", "Sell Out


AMT", "Inventory QTY"}),

RMNONACTIVE = Table.SelectRows(RMNULL, each (([#"Inventory QTY"]+[#"Sell Out QTY"]+[#"Sell Out AMT"]) <>
0)),

#"Added Custom" = Table.AddColumn(RMNONACTIVE, "MTH_NUM", each


Date.Month(Date.AddMonths(Date.FromText("1-"&[Month]),-3))),

#"Filtered Rows3" = Table.SelectRows(#"Added Custom", each [MTH_NUM] > actmonth),

#"Removed Columns2" = Table.RemoveColumns(#"Filtered Rows3",{"MTH_NUM"})

in

#"Removed Columns2"

/*RMNONACTIVE*/
Parameter Value
CUR_FY 2021
ACT_MTH APR
FCT_MTH MAY
FCT_PATH C:\RobotWorkspace\01. Projects\SPU\ElCondor\FCT\FY21\FCT_202105
MPCOST_PATH C:\RobotWorkspace\01. Projects\SPU\ElCondor\MP Cost\FY21\MP_COST_LFCT.xlsx
SRLAFCT_SRC ROLLING
COUNTRY SPU
'18.2020','22.2020','26.2020','31.2020','35.2020','39.2020','44.2020','48.2020','53.2020',
WEEKS_INV '04.2021'

ACT_DM

let

weeks_inv = List.RemoveMatchingItems(List.Distinct(Text.SplitAny( fnGetParameter("WEEKS_INV") , "','")),{""}),

Actmonth = if fnGetParameter("ACT_MTH")=null then 0 else Date.Month(Date.AddMonths(Date.FromText("1-"&


fnGetParameter("ACT_MTH")),-3)),

CurrFY = "FY" & Text.End(Text.From(fnGetParameter("CUR_FY")),2),

Path = "C:\RobotWorkspace\01. Projects\SPU\ElCondor\ACT\FY_SELLOUT",

/* Open file from actual Triple Queries folder, filtering current FY */

Source = Folder.Files(Path),

Filter_XlsFiles = Table.SelectRows(Source, each ([Extension] = ".xlsm" and not Text.Contains([Name], "~$"))),

Filter_CY = Table.SelectRows(Filter_XlsFiles, each (Text.Start([Name],4) = CurrFY)),

ADDCOL_GetExcelData = Table.AddColumn(Filter_CY, "Custom", each Excel.Workbook([Content])),

EXPAND_ShowWorkbookItems = Table.ExpandTableColumn(ADDCOL_GetExcelData, "Custom", {"Name", "Data",


"Item", "Kind", "Hidden"}, {"Custom.Name", "Custom.Data", "Custom.Item", "Custom.Kind", "Custom.Hidden"}),

FILTER_KeepOnlyTripleDataGrid = Table.SelectRows(EXPAND_ShowWorkbookItems, each ([Custom.Item] =


"DF_GRID_1")),

#"Added Custom33" = Table.AddColumn(FILTER_KeepOnlyTripleDataGrid, "Custom", each


Table.PromoteHeaders([Custom.Data])),

#"Removed Other Columns" = Table.SelectColumns(#"Added Custom33",{"Custom"}),

#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Calendar year /


week", "Calendar Year/Month", "Payer", "", "Point of Sales", "_1", "Material group", "_2", "Material Number", "Key
Figures", "#(lf)Sell-Out Qty", "#(lf)Dealear Stock Qty", "#(lf)Sell-Out Amt"}, {"Calendar year / week", "Calendar
Year/Month", "Payer", "", "Point of Sales", "_1", "Material group", "_2", "Material Number", "Key Figures", "#(lf)Sell-
Out Qty", "#(lf)Dealear Stock Qty", "#(lf)Sell-Out Amt"}),
filter_stock = Table.AddColumn(#"Expanded Custom", "col", each if List.Contains(weeks_inv, [#"Calendar year /
week"]) then [#"#(lf)Dealear Stock Qty"] else 0 ),

#"Replaced Value1" = Table.ReplaceValue(filter_stock,null,0,Replacer.ReplaceValue,{"#(lf)Sell-Out Qty", "col",


"#(lf)Sell-Out Amt"}),

#"Grouped Rows" = Table.Group(#"Replaced Value1", {"Payer", "", "Point of Sales", "_1", "Material group", "_2",
"Material Number", "Key Figures", "Calendar Year/Month"}, {{"Sell-Out Qty", each List.Sum([#"#(lf)Sell-Out Qty"]),
type number}, {"Dealer Stock Qty", each List.Sum([col]), type number}, {"Sell-Out Amt", each List.Sum([#"#(lf)Sell-
Out Amt"]), type number}}),

#"Unpivoted Columns1" = Table.UnpivotOtherColumns(#"Grouped Rows", {"Calendar Year/Month", "Payer", "",


"Point of Sales", "_1", "Material group", "_2", "Material Number", "Key Figures"}, "Attribute", "Value"),

#"Filtered Rows3" = Table.SelectRows(#"Unpivoted Columns1", each ([#"Calendar Year/Month"] <> "Result")),

#"Pivoted Column1" = Table.Pivot(#"Filtered Rows3", List.Distinct(#"Filtered Rows3"[#"Calendar Year/Month"]),


"Calendar Year/Month", "Value", List.Sum),

#"Renamed Columns22" = Table.RenameColumns(#"Pivoted Column1",{{"", "Dealer"}, {"_1", "Store Code"}, {"_2",


"Category"}, {"Key Figures", "Model Name"}, {"Attribute", "Calendar Year/Month"}}),

#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Renamed Columns22", {"Payer", "Dealer", "Point of Sales",


"Store Code", "Material group", "Category", "Material Number", "Model Name", "Calendar Year/Month"},
"Attribute", "Value"),

#"Renamed Columns1" = Table.RenameColumns(#"Unpivoted Columns",{{"Material group", "6D Code"},{"Material


Number", "8D Code"},{"Dealer", "Payer Name"},{"Payer", "Payer Code"},{"Attribute", "MMYYYY"}, {"Calendar
Year/Month", "Figures"}}),

#"Pivoted Column" = Table.Pivot(#"Renamed Columns1", List.Distinct(#"Renamed Columns1"[Figures]), "Figures",


"Value", List.Sum),

#"Split Column by Delimiter" = Table.SplitColumn(#"Pivoted Column","MMYYYY",Splitter.SplitTextByDelimiter(".",


QuoteStyle.Csv),{"MonthNumber", "CY"}),

#"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"MonthNumber", Int64.Type},


{"CY", Int64.Type}, {"Sell-Out Qty", type number}, {"Sell-Out Amt", type number}, {"Dealer Stock Qty", type
number}}),

#"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Payer Name] <> "Sony Store - OFFLINE" and [Payer
Name] <> "Sony Store - ONLINE")),

#"Added Custom" = Table.AddColumn(#"Filtered Rows", "FY", each CurrFY),

#"Added Custom1" = Table.AddColumn(#"Added Custom", "Month", each Text.Upper(Date.ToText(#date([CY],


[MonthNumber],1),"MMM"))),

#"Added Custom11" = Table.AddColumn(#"Added Custom1", "Custom", each if Text.Contains([#"Point of


Sales"],"PARIS") then "66666" else [Payer Code], type text),

#"Removed Columns1" = Table.RemoveColumns(#"Added Custom11",{"MonthNumber", "CY","Payer Code"}),

#"Renamed Columns" = Table.RenameColumns(#"Removed Columns1",{{"Custom", "Payer Code"}}),


#"Added Custom2" = Table.AddColumn(#"Renamed Columns", "Ranging", each if ([Dealer Stock Qty]+[#"Sell-Out
Qty"]>0) then 1 else null),

GroupStoresbyDealer = Table.Group( #"Added Custom2", {"Payer Code","6D Code", "Category", "8D Code",
"Model Name", "FY", "Month"}, {

{"Sell Out AMT", each List.Sum([#"Sell-Out Amt"]), type number},

{"Sell Out QTY", each List.Sum([#"Sell-Out Qty"]), type number},

{"Inventory QTY", each List.Sum([Dealer Stock Qty]), type number},

{"Ranging", each List.Sum([Ranging]), type number}}),

#"Merged Queries" = Table.NestedJoin(GroupStoresbyDealer,{"Payer Code"},DEALER_MASTER,{"Payer


Code"},"NewColumn",JoinKind.LeftOuter),

#"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"Country",


"Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"},
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer
Name"}),

#"Removed Columns2" = Table.RemoveColumns(#"Expanded NewColumn",{"6D Code"}),

#"Extracted First Characters" = Table.TransformColumns(#"Removed Columns2", {{"FY", each _ & " " &
Text.From(Date.Month(Date.FromText("1-"& fnGetParameter("FCT_MTH")))) & "F" , type text}}),

#"Added Custom3" = Table.AddColumn(#"Extracted First Characters", "Custom", each try


Number.ToText(Number.From([8D Code]),"00000000") otherwise [8D Code]),

#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom3",{{"Custom", type text}}),

#"Removed Columns3" = Table.RemoveColumns(#"Changed Type1",{"8D Code"}),

#"Renamed Columns2" = Table.RenameColumns(#"Removed Columns3",{{"Custom", "8D Code"}}),

#"Added Custom4" = Table.AddColumn(#"Renamed Columns2", "First Characters", each Text.Start([FY], 4)),

#"Merged Queries1" = Table.NestedJoin(#"Added Custom4",{"Month"},MM,


{"MONTH"},"NewColumn",JoinKind.LeftOuter),

#"Expanded NewColumn1" = Table.ExpandTableColumn(#"Merged Queries1", "NewColumn", {"MM"},


{"NewColumn.MM"}),

#"Replaced Value" = Table.ReplaceValue(#"Expanded NewColumn1","FY","20",Replacer.ReplaceText,{"First


Characters"}),

#"Added Custom5" = Table.AddColumn(#"Replaced Value", "Custom", each [First Characters]&[NewColumn.MM]),

#"Changed Type3" = Table.TransformColumnTypes(#"Added Custom5",{{"NewColumn.MM", Int64.Type}}),

#"Filtered Rows1" = Table.SelectRows(#"Changed Type3", each (Date.Month(Date.AddMonths(Date.FromText("1-"


& [Month], "En-US"),-3)) <= Actmonth)),

#"Removed Columns4" = Table.RemoveColumns(#"Filtered Rows1",{"First Characters", "NewColumn.MM"}),

#"Renamed Columns3" = Table.RenameColumns(#"Removed Columns4",{{"Custom", "FYMM"}}),

#"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns3",{"Payer Code", "Category", "8D Code",


"Model Name", "FY", "Month", "Ranging", "Country", "Company", "Channel Group", "Channel", "Dealer Group",
"Dealer", "Koro Name", "Store", "Payer Name", "Sell Out QTY", "Inventory QTY", "Sell Out AMT"}),

#"Appended Query" = Table.Combine({#"Reordered Columns", #"EV BUNDLE"})


in

#"Appended Query"

ACT_SS

let

/* Actual FY Month Number (e.g. APR = 1, MAR = 12) */

ActMonth = if fnGetParameter("ACT_MTH")=null then 0 else Date.Month(Date.AddMonths(Date.FromText("1-"&


fnGetParameter("ACT_MTH")),-3)),

/* Open file from actual Triple Queries folder, filtering current FY */

Source = Folder.Files("C:\RobotWorkspace\01. Projects\SPU\ElCondor\ACT\TRIPLE_QUERIES"),

#"Filtered Rows2" = Table.SelectRows(Source, each ([Name] <> ".cekey" and not Text.Contains([Name], "~$") and
not Text.Contains([Name], "_CL30"))),

#"Filtered Rows" = Table.SelectRows(#"Filtered Rows2", each ([Name] = "FY20_SPU_1H.xlsm" or [Name] =


"FY20_SPU_2H.xlsm")),

#"Removed Other Columns1" = Table.SelectColumns(#"Filtered Rows",{"Content", "Name"}),

#"Added Custom" = Table.AddColumn(#"Removed Other Columns1", "Custom", each Excel.Workbook([Content])),

#"Replaced Value3" = Table.ReplaceValue(#"Added Custom",".xlsm","",Replacer.ReplaceText,{"Name"}),

#"Replaced Value" = Table.ReplaceValue(#"Replaced Value3","_1H","",Replacer.ReplaceText,{"Name"}),

#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","_SPU","",Replacer.ReplaceText,{"Name"}),

#"Replaced Value2" = Table.ReplaceValue(#"Replaced Value1","_2H","",Replacer.ReplaceText,{"Name"}),

#"Expanded Custom" = Table.ExpandTableColumn(#"Replaced Value2", "Custom", {"Name", "Data", "Item",


"Kind", "Hidden"}, {"Custom.Name", "Custom.Data", "Custom.Item", "Custom.Kind", "Custom.Hidden"}),

#"Filtered Rows3" = Table.SelectRows(#"Expanded Custom", each ([Custom.Item] = "DF_GRID_1")),

#"Added Custom1" = Table.AddColumn(#"Filtered Rows3", "ExclHeaders", each


Table.PromoteHeaders(Table.PromoteHeaders([Custom.Data]))),

#"Removed Columns1" = Table.RemoveColumns(#"Added Custom1",{"Custom.Name", "Custom.Item",


"Custom.Kind", "Custom.Hidden", "Content", "Custom.Data"}),

#"Expanded ExclHeaders" = Table.ExpandTableColumn(#"Removed Columns1", "ExclHeaders", {"Fiscal Period",


"Payer", "", "Material Group (Recateg)", "_1", "Material Number", "_2", "Ship-to Party", "Gross Sales", "On Invoice
Discount", "Outside Sales & Operating Revenue", "GP", "Gross Sales_3", "On Invoice Discount_4", "Outside Sales &
Operating Revenue_5", "GP_6", "Gross Sales_7", "On Invoice Discount_8", "Outside Sales & Operating Revenue_9",
"GP_10"}, {"Fiscal Period", "Payer", "Column1", "Material Group (Recateg)", "_1", "Material Number", "_2", "Ship-to
Party", "Gross Sales", "On Invoice Discount", "Outside Sales & Operating Revenue", "GP", "Gross Sales_3", "On
Invoice Discount_4", "Outside Sales & Operating Revenue_5", "GP_6", "Gross Sales_7", "On Invoice Discount_8",
"Outside Sales & Operating Revenue_9", "GP_10"}),
#"Added Custom4" = Table.AddColumn(#"Expanded ExclHeaders", "Custom", each if [#"Ship-to
Party"]="D07004748" then "66666" else [Payer], type text),

#"Removed Columns3" = Table.RemoveColumns(#"Added Custom4",{"Payer", "Ship-to Party"}),

#"Renamed Columns3" = Table.RenameColumns(#"Removed Columns3",{{"Custom", "Payer"}}),

#"Renamed Columns" = Table.RenameColumns(#"Renamed Columns3",{{"Name", "FY"}, {"Column1", "Dealer"},


{"_1", "Category"}, {"_2", "Descripcion"}, {"Outside Sales & Operating Revenue", "Net Sales (LC)"}, {"GP", "GP (LC)"},
{"Outside Sales & Operating Revenue_5", "Net Sales (USD)"}, {"GP_6", "GP (USD)"}, {"Outside Sales & Operating
Revenue_9", "Qty"}, {"Gross Sales", "Gross Sales (LC)"}, {"Gross Sales_3", "Gross Sales (USD)"}}),

#"Replaced Value5" = Table.ReplaceValue(#"Renamed Columns",null,0,Replacer.ReplaceValue,{"Gross Sales (LC)",


"On Invoice Discount", "Net Sales (LC)", "GP (LC)", "Gross Sales (USD)", "On Invoice Discount_4", "Net Sales (USD)",
"GP (USD)", "Qty"}),

#"Removed Columns" = Table.RemoveColumns(#"Replaced Value5",{"Gross Sales_7", "GP_10", "On Invoice


Discount", "On Invoice Discount_4", "On Invoice Discount_8", "Gross Sales (LC)", "GP (LC)", "Gross Sales (USD)", "Net
Sales (USD)", "GP (USD)"}),

/* 8D Code adjustment: Set 8 Digits for all numerical codes (e.g. 123456->00123456, R123456->R123456) */

#"Renamed Columns2" = Table.RenameColumns(#"Removed Columns",{{"Fiscal Period", "Month"}, {"Material


Group (Recateg)", "6D Code"}, {"Material Number", "8D Code"}, {"Payer", "Payer Code"}, {"Dealer", "Payer Name"},
{"Descripcion", "Model Name"}}),

Adjust8Dcode = Table.AddColumn(#"Renamed Columns2", "8D Code1", each try


Number.ToText(Number.From([8D Code]),"00000000") otherwise [8D Code]),

swapnames = Table.RenameColumns(Adjust8Dcode,{{"8D Code", "DEL"}, {"8D Code1", "8D Code"}}),

#"del del" = Table.RemoveColumns(swapnames,{"DEL"}),

#"Reordered Columns" = Table.ReorderColumns(#"del del",{"FY", "Month", "Payer Code", "Payer Name", "6D
Code", "Category", "8D Code", "Model Name", "Net Sales (LC)", "Qty"}),

#"Grouped Rows" = Table.Group(#"Reordered Columns", {"FY", "Month", "Payer Code", "Payer Name", "6D Code",
"Category", "8D Code", "Model Name"}, { {"Net Sales (LC)", each List.Sum([#"Net Sales (LC)"]), type number}, {"Qty",
each List.Sum([Qty]), type number}}),

/* ---- SKIP --- Product categorization: Add Subcategory, Technology, Series fields from 8D code

#"Merged Queries1" = Table.NestedJoin(#"Renamed Columns1",{"8D Code"},PROD_MASTER,{"8D


Code"},"NewColumn",JoinKind.LeftOuter),

#"Expanded NewColumn1" = Table.ExpandTableColumn(#"Merged Queries1", "NewColumn", {"Sub Categories",


"TECHNOLOGY1", "SERIES"}, {"Sub Categories", "TECHNOLOGY1", "SERIES"}),

*/

/* Dealer Categorization: Add dealer fields from payer code. *Set #(Not Assigned) for all non Key Dealers for
grouping purpose*/

#"Added Custom3" = Table.AddColumn(#"Grouped Rows", "Payer Code Chk", each if


List.Contains(DEALER_MASTER[Payer Code], [Payer Code]) then [Payer Code] else "#"),

#"Merged Queries2" = Table.NestedJoin(#"Added Custom3",{"Payer Code Chk"},DEALER_MASTER,{"Payer


Code"},"NewColumn",JoinKind.LeftOuter),
#"Removed Columns2" = Table.RemoveColumns(#"Merged Queries2",{"Payer Code Chk", "Payer Code", "Payer
Name"}),

#"Expanded NewColumn3" = Table.ExpandTableColumn(#"Removed Columns2", "NewColumn", {"SC","Country",


"Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name", "Payer
Code"}, {"SC","Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store",
"Payer Name", "Payer Code"}),

#"Filtered Rows5" = Table.SelectRows(#"Expanded NewColumn3", each ([Koro Name] = "CHANCAFE" or [Koro


Name] = "COUNTRY" or [Koro Name] = "E-COMMERCE" or [Koro Name] = "JOCKEY PLAZA" or [Koro Name] = "SIMA"
or [Koro Name] = "SONY RETAIL")),

SET_FY = Table.TransformColumns(#"Filtered Rows5", {{"FY", each _ & " " &


Text.From(Date.Month(Date.FromText("1-"& fnGetParameter("FCT_MTH")))) & "F" , type text}}),

RMNULL = Table.ReplaceValue(SET_FY,null,0,Replacer.ReplaceValue,{"Qty", "Net Sales (LC)"}),

RMNONACTIVE = Table.SelectRows(RMNULL, each (([#"Qty"]) <> 0)),

#"Reordered Columns1" = Table.ReorderColumns(RMNONACTIVE,{"Payer Code", "Category", "8D Code", "Model


Name", "FY", "Month", "6D Code", "Qty", "SC", "Country", "Company", "Channel Group", "Channel", "Dealer Group",
"Dealer", "Koro Name", "Store", "Payer Name"}),

#"Removed Columns5" = Table.RemoveColumns(#"Reordered Columns1",{"6D Code", "SC"}),

#"Reordered Columns2" = Table.ReorderColumns(#"Removed Columns5",{"Payer Code", "Category", "8D Code",


"Model Name", "FY", "Month", "Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro
Name", "Store", "Payer Name", "Qty","Net Sales (LC)"}),

#"Renamed Columns1" = Table.RenameColumns(#"Reordered Columns2",{{"Qty", "Sell Out QTY"},{"Net Sales


(LC)", "Sell Out AMT"}}),

#"Added Custom2" = Table.AddColumn(#"Renamed Columns1", "Inventory QTY", each 0),

#"Added Custom7" = Table.AddColumn(#"Added Custom2", "Ranging", each 1),

#"Filtered Rows4" = Table.SelectRows(#"Added Custom7", each


(Date.Month(Date.AddMonths(Date.FromText("1-" & [Month], "En-US"),-3)) <= ActMonth)),

#"Multiplied Column" = Table.TransformColumns(#"Filtered Rows4", {{"Sell Out AMT", each _ * 100, type
number}})

in

#"Multiplied Column"

EV BUNDLE

let

weeks_inv = List.RemoveMatchingItems(List.Distinct(Text.SplitAny( fnGetParameter("WEEKS_INV") , "','")),{""}),

Actmonth = if fnGetParameter("ACT_MTH")=null then 0 else Date.Month(Date.AddMonths(Date.FromText("1-"&


fnGetParameter("ACT_MTH")),-3)),

CurrFY = "FY" & Text.End(Text.From(fnGetParameter("CUR_FY")),2),

Path = "C:\RobotWorkspace\01. Projects\SPU\ElCondor\ACT\FY_SELLOUT",


/* Open file from actual Triple Queries folder, filtering current FY */

Source = Folder.Files(Path),

Filter_XlsFiles = Table.SelectRows(Source, each ([Extension] = ".xlsm" and not Text.Contains([Name], "~$"))),

Filter_CY = Table.SelectRows(Filter_XlsFiles, each (Text.Start([Name],4) = CurrFY)),

ADDCOL_GetExcelData = Table.AddColumn(Filter_CY, "Custom", each Excel.Workbook([Content])),

EXPAND_ShowWorkbookItems = Table.ExpandTableColumn(ADDCOL_GetExcelData, "Custom", {"Name", "Data",


"Item", "Kind", "Hidden"}, {"Custom.Name", "Custom.Data", "Custom.Item", "Custom.Kind", "Custom.Hidden"}),

FILTER_KeepOnlyTripleDataGrid = Table.SelectRows(EXPAND_ShowWorkbookItems, each ([Custom.Item] =


"DF_GRID_1")),

#"Added Custom33" = Table.AddColumn(FILTER_KeepOnlyTripleDataGrid, "Custom", each


Table.PromoteHeaders([Custom.Data])),

#"Removed Other Columns" = Table.SelectColumns(#"Added Custom33",{"Custom"}),

#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Calendar year /


week", "Calendar Year/Month", "Payer", "", "Point of Sales", "_1", "Material group", "_2", "Material Number", "Key
Figures", "#(lf)Sell-Out Qty", "#(lf)Dealear Stock Qty", "#(lf)Sell-Out Amt"}, {"Calendar year / week", "Calendar
Year/Month", "Payer", "Dealer", "Point of Sales", "_1", "Material group", "_2", "Material Number", "Key Figures",
"#(lf)Sell-Out Qty", "#(lf)Dealear Stock Qty", "#(lf)Sell-Out Amt"}),

#"Filtered Rows" = Table.SelectRows(#"Expanded Custom", each ([Dealer] = "CONECTA RETAIL S.A." or [Dealer] =
"ELECTROTIENDAS DEL PERU S.A.C." or [Dealer] = "GMG COMERCIAL PERU S.A") and ([_2] = "CAR AFTER")),

filter_stock = Table.AddColumn(#"Filtered Rows", "col", each if List.Contains(weeks_inv, [#"Calendar year /


week"]) then [#"#(lf)Dealear Stock Qty"] else 0 ),

#"Replaced Value1" = Table.ReplaceValue(filter_stock,null,0,Replacer.ReplaceValue,{"#(lf)Sell-Out Qty", "col",


"#(lf)Sell-Out Amt"}),

#"Grouped Rows" = Table.Group(#"Replaced Value1", {"Payer", "Dealer", "Point of Sales", "_1", "Material group",
"_2", "Material Number", "Key Figures", "Calendar Year/Month"}, {{"Sell-Out Qty", each List.Sum([#"#(lf)Sell-Out
Qty"]), type number}, {"Dealer Stock Qty", each List.Sum([col]), type number}, {"Sell-Out Amt", each
List.Sum([#"#(lf)Sell-Out Amt"]), type number}}),

#"Renamed Columns22" = Table.RenameColumns(#"Grouped Rows",{{"_1", "Store Code"}, {"_2", "Category"},


{"Key Figures", "Model Name"}}),

#"Renamed Columns1" = Table.RenameColumns(#"Renamed Columns22",{{"Material group", "6D Code"},{"Material


Number", "8D Code"},{"Dealer", "Payer Name"},{"Payer", "Payer Code"}, {"Calendar Year/Month", "MMYYYY"}}),

#"Split Column by Delimiter" = Table.SplitColumn(#"Renamed


Columns1","MMYYYY",Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv),{"MonthNumber", "CY"}),

#"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"MonthNumber", Int64.Type},


{"CY", Int64.Type}, {"Sell-Out Qty", type number}, {"Sell-Out Amt", type number}, {"Dealer Stock Qty", type
number}}),
#"Merged Queries5" = Table.NestedJoin(#"Changed Type",{"Payer Code"},DEALER_MASTER,{"Payer
Code"},"DEALER_MASTER",JoinKind.LeftOuter),

#"Expanded DEALER_MASTER" = Table.ExpandTableColumn(#"Merged Queries5", "DEALER_MASTER", {"Dealer"},


{"DEALER"}),

#"Merged Queries4" = Table.NestedJoin(#"Expanded DEALER_MASTER",{"8D Code", "DEALER"},BUNDLE,{"MU_8D


CODE", "DEALER"},"NewColumn",JoinKind.Inner),

#"Expanded NewColumn4" = Table.ExpandTableColumn(#"Merged Queries4", "NewColumn", {"CODE1",


"MODEL1"}, {"CODE1", "MODEL1"}),

#"Added Custom" = Table.AddColumn(#"Expanded NewColumn4", "FY", each CurrFY),

#"Added Custom1" = Table.AddColumn(#"Added Custom", "Month", each Text.Upper(Date.ToText(#date([CY],


[MonthNumber],1),"MMM"))),

#"Removed Columns1" = Table.RemoveColumns(#"Added Custom1",{"MonthNumber", "CY"}),

#"Added Custom2" = Table.AddColumn(#"Removed Columns1", "Ranging", each if ([Dealer Stock Qty]+[#"Sell-Out


Qty"]>0) then 1 else null),

GroupStoresbyDealer = Table.Group( #"Added Custom2", {"Payer Code","6D Code", "Category", "FY", "Month",
"CODE1","MODEL1"}, {

{"Sell Out QTY", each List.Sum([#"Sell-Out Qty"]), type number}, {"Sell Out AMT", each List.Sum([#"Sell-
Out Amt"]), type number},

{"Inventory QTY", each List.Sum([Dealer Stock Qty]), type number},

{"Ranging", each List.Sum([Ranging]), type number}}),

#"Renamed Columns" = Table.RenameColumns(GroupStoresbyDealer,{{"CODE1", "8D Code"}, {"MODEL1", "Model


Name"}}),

#"Merged Queries" = Table.NestedJoin(#"Renamed Columns",{"Payer Code"},DEALER_MASTER,{"Payer


Code"},"NewColumn",JoinKind.LeftOuter),

#"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"Country",


"Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"},
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer
Name"}),

#"Removed Columns2" = Table.RemoveColumns(#"Expanded NewColumn",{"6D Code"}),

#"Extracted First Characters" = Table.TransformColumns(#"Removed Columns2", {{"FY", each _ & " " &
Text.From(Date.Month(Date.FromText("1-"& fnGetParameter("FCT_MTH")))) & "F" , type text}}),

#"Added Custom3" = Table.AddColumn(#"Extracted First Characters", "Custom", each try


Number.ToText(Number.From([8D Code]),"00000000") otherwise [8D Code]),

#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom3",{{"Custom", type text}}),

#"Removed Columns3" = Table.RemoveColumns(#"Changed Type1",{"8D Code"}),

#"Renamed Columns2" = Table.RenameColumns(#"Removed Columns3",{{"Custom", "8D Code"}}),

#"Added Custom4" = Table.AddColumn(#"Renamed Columns2", "First Characters", each Text.Start([FY], 4)),

#"Merged Queries1" = Table.NestedJoin(#"Added Custom4",{"Month"},MM,


{"MONTH"},"NewColumn",JoinKind.LeftOuter),
#"Expanded NewColumn1" = Table.ExpandTableColumn(#"Merged Queries1", "NewColumn", {"MM"},
{"NewColumn.MM"}),

#"Replaced Value" = Table.ReplaceValue(#"Expanded NewColumn1","FY","20",Replacer.ReplaceText,{"First


Characters"}),

#"Added Custom5" = Table.AddColumn(#"Replaced Value", "Custom", each [First Characters]&[NewColumn.MM]),

#"Changed Type3" = Table.TransformColumnTypes(#"Added Custom5",{{"NewColumn.MM", Int64.Type}}),

#"Filtered Rows1" = Table.SelectRows(#"Changed Type3", each (Date.Month(Date.AddMonths(Date.FromText("1-"


& [Month], "En-US"),-3)) <= Actmonth)),

#"Removed Columns4" = Table.RemoveColumns(#"Filtered Rows1",{"First Characters", "NewColumn.MM"}),

#"Renamed Columns3" = Table.RenameColumns(#"Removed Columns4",{{"Custom", "FYMM"}}),

#"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns3",{"Payer Code", "Category", "8D Code",


"Model Name", "FY", "Month", "Ranging", "Country", "Company", "Channel Group", "Channel", "Dealer Group",
"Dealer", "Koro Name", "Store", "Payer Name", "Sell Out QTY", "Sell Out AMT", "Inventory QTY"})

in

#"Reordered Columns"

DEALER_MASTER

let

Source = Excel.Workbook(File.Contents("C:\RobotWorkspace\01. Projects\SPU\ElCondor\Mapping


tables\HiearchyMaster.xlsx"), null, true),

#"Dealer _Sheet" = Source{[Item="Dealer ",Kind="Sheet"]}[Data],

#"Changed Type" = Table.TransformColumnTypes(#"Dealer _Sheet",{{"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}}),

#"Promoted Headers" = Table.PromoteHeaders(#"Changed Type"),

#"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each ([Payer Code] <> "Not Used")),

#"Removed Duplicates" = Table.Distinct(#"Filtered Rows", {"Payer Code"}),

#"Changed Type1" = Table.TransformColumnTypes(#"Removed Duplicates",{{"Payer Code", type text}})

in

#"Changed Type1"

CLUSTER_MASTER

let

Source = Excel.Workbook(File.Contents("C:\RobotWorkspace\01. Projects\SPU\ElCondor\Mapping


tables\ClusterMaster.xlsx"), null, true),

TBL_CLUSTERMAP_Table = Source{[Item="TBL_CLUSTERMAP",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(TBL_CLUSTERMAP_Table,{{"PAYER_CODE", type text},
{"DEALER_NAME", type text}, {"CLUSTER", type text}, {"STORE_NUMBER", type text}, {"POINT_OF_SALES", type text},
{"STORE_NAME", type text}})

in

#"Changed Type"

PROD_MASTER

let

Source = Excel.Workbook(File.Contents("C:\RobotWorkspace\01. Projects\SPU\ElCondor\Mapping


tables\Categorization2.xlsx"), null, true),

Hoja1_Sheet = Source{[Item="Categorization",Kind="Table"]}[Data],

#"Changed Type2" = Table.TransformColumnTypes(Hoja1_Sheet,{{"Representative 8D Code", type text},


{"Representative Description", type text}, {"Material Number", type text}, {"MODEL", type text}, {"CATEGORY", type
text}, {"SUB CATEGORY", type text}, {"SEGMENT1", type text}, {"SEGMENT2", type text}, {"SERIES", type text},
{"MODEL STATUS", type text}, {"6D Code", type text}}),

#"MPADJ - Adjust MP code" = Table.RemoveColumns(Table.AddColumn(#"Changed Type2", "8D Code", each try


Number.ToText(Number.From([Material Number]),"00000000") otherwise [Material Number]),{"Material
Number"}),

#"Reordered Columns" = Table.ReorderColumns(#"MPADJ - Adjust MP code",{"Representative Description",


"CATEGORY", "SUB CATEGORY","SEGMENT1", "SEGMENT2", "SERIES", "8D Code", "MODEL"}),

#"Added Custom" = Table.AddColumn(#"Reordered Columns", "Representative 8D Code_1", each try


Number.ToText(Number.From([Representative 8D Code]),"00000000") otherwise [Representative 8D Code]),

#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"8D Code", type text}, {"Representative 8D


Code_1", type text}})

in

#"Changed Type1"

FCT_CONSOLIDATED_ADJ

let

Source = #"WEEKLY_SELLOUT",

#"Merged Queries" = Table.NestedJoin(Source,{"FY", "WEEK", "CALENDAR YEAR"},WEEK_SPLIT,{"FISCAL YEAR",


"SPLIT WK", "CALENDAR YEAR"},"NewColumn",JoinKind.Inner),

#"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"ORIGINAL MONTH",


"DAYS"}, {"MONTH.1", "DAYS"}),

#"Reordered Columns" = Table.ReorderColumns(#"Expanded NewColumn",{"FY", "Category", "WEEK", "Country",


"Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Payer Code", "Payer Name", "MODEL",
"Representative 8D Code_1", "Sub Category", "Koro Name", "Store", "MONTH.1", "SELLOUT (QTY)", "DAYS"}),

#"Added Custom" = Table.AddColumn(#"Reordered Columns", "OFFSET", each [#"SELLOUT (QTY)"]/7*[DAYS]),


#"Added CustomADJ" = Table.AddColumn(#"Added Custom", "OFFSET_AMT", each [#"Sell Out AMT"]/7*[DAYS]),
#"Grouped Rows" = Table.Group(#"Added CustomADJ", {"Category", "Country", "Company", "Channel Group",
"Channel", "Dealer Group", "Dealer", "Payer Code", "Payer Name", "MODEL", "Representative 8D Code_1",
"MONTH.1", "Sub Category","SEGMENT1", "FY", "Koro Name", "Store"}, {{"SELLOUT (QTY)", each List.Sum([OFFSET]),
type number},{"Sell Out AMT", each List.Sum([OFFSET_AMT]), type number}}),

#"Renamed Columns" = Table.RenameColumns(#"Grouped Rows",{{"MONTH.1", "Month"}, {"SELLOUT (QTY)",


"Sell Out QTY"}, {"MODEL", "Model Name"}, {"Representative 8D Code_1", "8D Code"}}),

#"Reordered Columns1" = Table.ReorderColumns(#"Renamed Columns",{"Country", "Company", "Channel


Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name", "Payer Code", "Category", "Sub
Category","SEGMENT1", "8D Code", "Model Name", "FY", "Month", "Sell Out QTY","Sell Out AMT"})

in

#"Reordered Columns1"

WEEKLY_SELLOUT

/*

let

Source = Folder.Files("C:\RobotWorkspace\01. Projects\SCI\ElCondor\ACT\WEEKLY_MARKET"),

#"Filtered Rows" = Table.SelectRows(Source, each ([Name] = "FY17.xlsm")),

#"Added Custom" = Table.AddColumn(#"Filtered Rows", "Custom", each Excel.Workbook([Content])),

#"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),

#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Name", "Data",


"Item", "Kind", "Hidden"}, {"Name.1", "Data", "Item", "Kind", "Hidden"}),

#"Filtered Rows1" = Table.SelectRows(#"Expanded Custom", each ([Name.1] = "DF_GRID_1")),

#"Removed Other Columns1" = Table.SelectColumns(#"Filtered Rows1",{"Data"}),

#"Expanded Data" = Table.ExpandTableColumn(#"Removed Other Columns1", "Data", {"Column1", "Column2",


"Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11",
"Column12", "Column13", "Column14", "Column15", "Column16", "Column17", "Column18", "Column19",
"Column20", "Column21", "Column22", "Column23", "Column24", "Column25", "Column26", "Column27",
"Column28", "Column29", "Column30", "Column31", "Column32", "Column33", "Column34", "Column35",
"Column36", "Column37", "Column38", "Column39"}, {"Column1", "Column2", "Column3", "Column4", "Column5",
"Column6", "Column7", "Column8", "Column9", "Column10", "Column11", "Column12", "Column13", "Column14",
"Column15", "Column16", "Column17", "Column18", "Column19", "Column20", "Column21", "Column22",
"Column23", "Column24", "Column25", "Column26", "Column27", "Column28", "Column29", "Column30",
"Column31", "Column32", "Column33", "Column34", "Column35", "Column36", "Column37", "Column38",
"Column39"}),

#"Promoted Headers" = Table.PromoteHeaders(#"Expanded Data"),

#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"Payer", "Dealer", "Material


group", "Category", "Material Number", "Model Name", "Calendar year / week"}, "Attribute", "Value"),

#"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Payer", type text}, {"Dealer",


type text}, {"Material group", type text}, {"Category", type text}, {"Material Number", type text}, {"Model Name",
type text}, {"Calendar year / week", type text}, {"Attribute", type text}, {"Value", type number}})

in

#"Changed Type"

*/
let

actmonth = if fnGetParameter("ACT_MTH")=null then 0 else Date.Month(Date.AddMonths(Date.FromText("1-"&


fnGetParameter("ACT_MTH")),-3)),

Source = Folder.Files("C:\RobotWorkspace\01. Projects\SPU\ElCondor\ACT\FY_SELLOUT"),

#"Filtered Rows" = Table.SelectRows(Source, each Text.Contains([Name], "FY19")),

#"Added Custom" = Table.AddColumn(#"Filtered Rows", "Custom", each Excel.Workbook([Content])),

#"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),

#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Name", "Data",


"Item", "Kind", "Hidden"}, {"Name.1", "Data", "Item", "Kind", "Hidden"}),

#"Filtered Rows1" = Table.SelectRows(#"Expanded Custom", each ([Name.1] = "DF_GRID_1")),

#"Added Custom2" = Table.AddColumn(#"Filtered Rows1", "Custom", each Table.PromoteHeaders([Data])),

#"Removed Other Columns1" = Table.SelectColumns(#"Added Custom2",{"Custom"}),

#"Expanded Custom3" = Table.ExpandTableColumn(#"Removed Other Columns1", "Custom", {"Calendar year /


week", "Calendar Year/Month", "Payer", "", "Material group", "_2", "Material Number", "Key Figures", "#(lf)Sell-Out
Qty" , "#(lf)Sell-Out Amt"}, {"Calendar year / week", "Calendar Year/Month", "Payer", "Column1", "Material group",
"_2", "Material Number", "Key Figures", "#(lf)Sell-Out Qty", "Sell Out AMT"}),

#"Renamed Columns1" = Table.RenameColumns(#"Expanded Custom3",{{"Calendar year / week", "WEEK"},


{"Calendar Year/Month", "CALMONTH"}, {"Payer", "PAYER"}, {"Column1", "DEALER"}, {"Material group", "6D CODE"},
{"_2", "CATEGORY"}, {"Material Number", "8D CODE"}, {"Key Figures", "MODEL NAME"}}),

#"Replaced Value" = Table.ReplaceValue(#"Renamed Columns1",null,0,Replacer.ReplaceValue,{"#(lf)Sell-Out


Qty"}),

#"Grouped Rows" = Table.Group(#"Replaced Value", {"WEEK", "CALMONTH", "PAYER", "DEALER", "6D CODE",
"CATEGORY", "8D CODE", "MODEL NAME"}, {{"SELLOUT (QTY)", each List.Sum([#"#(lf)Sell-Out Qty"]), type number},
{"Sell Out AMT", each List.Sum([#"Sell Out AMT"]), type number}}),

#"Filtered Rows2" = Table.SelectRows(#"Grouped Rows", each ([DEALER] <> "Sony Store - OFFLINE" and [DEALER]
<> "Sony Store - ONLINE")),

#"Added Custom1" = Table.AddColumn(#"Filtered Rows2", "FY", each


"FY"&Text.End(Number.ToText(fnGetParameter("CUR_FY")),2)),

#"Changed Type" = Table.TransformColumnTypes(#"Added Custom1",{{"PAYER", type text}, {"DEALER", type text},


{"6D CODE", type text}, {"CATEGORY", type text}, {"8D CODE", type text}, {"MODEL NAME", type text}, {"WEEK", type
text}, {"SELLOUT (QTY)", type number}, {"CALMONTH", type text}, {"FY", type text}}),

#"Filtered Zero" = Table.SelectRows(#"Changed Type", each ([#"SELLOUT (QTY)"] <> 0)),

#"TRANSFORM TO 8D" = Table.TransformColumns(#"Filtered Zero", {{"8D CODE", each try


Number.ToText(Number.From(_),"00000000") otherwise _, type text}}),

#"Merged Queries" = Table.NestedJoin(#"TRANSFORM TO 8D",{"PAYER"},DEALER_MASTER,{"Payer


Code"},"NewColumn",JoinKind.LeftOuter),

#"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"Country",


"Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name", "Payer
Code"}, {"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store",
"Payer Name", "Payer Code"}),
#"Merged Queries1" = Table.NestedJoin(#"Expanded NewColumn",{"8D CODE"},PROD_MASTER,{"8D
Code"},"NewColumn",JoinKind.LeftOuter),

#"Removed Columns1" = Table.RemoveColumns(#"Merged Queries1",{"CATEGORY"}),

#"Expanded NewColumn2" = Table.ExpandTableColumn(#"Removed Columns1", "NewColumn", {"Representative


Description", "CATEGORY", "SUB CATEGORY", "SEGMENT1", "SERIES", "6D Code", "Representative 8D Code_1"},
{"MODEL", "Category", "Sub Category", "SEGMENT1", "SERIES", "6D Code.1", "Representative 8D Code_1"}),

#"Extracted First Characters1" = Table.TransformColumns(#"Expanded NewColumn2", {{"WEEK", each


"WK"&Text.Start(Text.From(_, "en-US"), 2), type text}}),

#"Extracted Last Characters" = Table.TransformColumns(#"Extracted First Characters1", {{"CALMONTH", each


Text.End(Text.From(_, "en-US"), 4), type text}}),

#"Renamed Columns" = Table.RenameColumns(#"Extracted Last Characters",{{"CALMONTH", "CALENDAR


YEAR"}}),

#"Removed Other Columns2" = Table.SelectColumns(#"Renamed Columns",{"CALENDAR YEAR","FY","Category",


"WEEK", "SELLOUT (QTY)","Sell Out AMT", "Country", "Company", "Channel Group", "Channel", "Dealer Group",
"Dealer","Payer Code","Payer Name", "MODEL", "Representative 8D Code_1","Sub
Category","SERIES","SEGMENT1","Koro Name","Store"}),

#"FY"= Table.TransformColumns(#"Removed Other Columns2", {{"FY", each _ & " " &
Text.From(Date.Month( Date.FromText("1-"& fnGetParameter("FCT_MTH")) )) & "F" , type text}})

in

FY

WEEK_SPLIT

let

actmonth = if fnGetParameter("FCT_MTH")=null then 0 else Date.Month( Date.FromText("1-"&


fnGetParameter("FCT_MTH")) ),

Source = Excel.CurrentWorkbook(){[Name="SPLIT"]}[Content],

#"Changed Type" = Table.TransformColumnTypes(Source,{{"FISCAL YEAR", type text}, {"SPLIT WK", Int64.Type},


{"ORIGINAL MONTH", type text}, {"MONTH", type text}, {"DAYS", Int64.Type}, {"CALENDAR YEAR", type text},
{"ACTIVE", Int64.Type}}),

#"Two Digit Week" = Table.TransformColumns(#"Changed Type", {{"SPLIT WK", each Number.ToText(_,"00"), type
text}}),

#"Extracted First Characters" = Table.TransformColumns(#"Two Digit Week", {{"SPLIT WK", each "WK"&_, type
text}}),

#"Filtered Rows" = Table.SelectRows(#"Extracted First Characters", each ([ACTIVE] = 1)),

#"Filtered Rows1" = Table.SelectRows(#"Filtered Rows", each ([FISCAL YEAR] =


"FY"&Text.End(Number.ToText(fnGetParameter("CUR_FY")),2))),

#"FY"= Table.TransformColumns(#"Filtered Rows1", {{"FISCAL YEAR", each _ & " " & Number.ToText(actmonth) &
"F" , type text}})
in

#"FY"

FCT_CONSOLIDATED

let

Source = Table.Combine({ROLLING_FCT_SUMMARY, ACT_DM, ACT_SS}),

#"Removed Columns" = Table.RemoveColumns(Source,{ "Category", "Sub Category", "SKU", "Model Name",


"SERIES"}),

#"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"8D Code", type text}}),

#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"8D Code", "8D Code_old"}}),

#"Merged Queries" = Table.NestedJoin(#"Renamed Columns",{"8D Code_old"},PROD_MASTER,{"8D


Code"},"NewColumn",JoinKind.LeftOuter),

#"Expanded NewColumn1" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"Representative


Description", "CATEGORY", "SUB CATEGORY", "SEGMENT1", "Representative 8D Code_1"}, {"Model Name",
"Category", "Sub Category", "SEGMENT1", "8D Code"}),

#"Removed Columns1" = Table.RemoveColumns(#"Expanded NewColumn1",{"8D Code_old"}),

#"Appended Query" = Table.Combine({#"Removed Columns1", FCT_CONSOLIDATED_ADJ}),

#"Filtered Rows" = Table.SelectRows(#"Appended Query", each ([Month] <> null)),

#"Renamed Columns1" = Table.RenameColumns(#"Filtered Rows",{{"Inventory QTY", "Channel Inv"}}),

#"Added Custom" = Table.AddColumn(#"Renamed Columns1", "SC", each "SPU"),

#"Renamed Columns2" = Table.RenameColumns(#"Added Custom",{{"8D Code", "Material Number"}}),

#"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns2",{"FY", "Month", "SC",


"Company","Country","Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name","Payer Code", "Payer
Name","Store", "Category", "Sub Category","SEGMENT1", "Material Number","Model Name","Sell Out QTY","Sell
Out AMT", "Channel Inv", "Ranging"}),

#"Replaced Value" = Table.ReplaceValue(#"Reordered Columns",null,0,Replacer.ReplaceValue,{"Sell Out QTY",


"Sell Out AMT", "Channel Inv", "Ranging"}),

#"Grouped Rows" = Table.Group(#"Replaced Value", {"FY", "Month", "SC", "Company", "Country", "Channel
Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Payer Code", "Payer Name", "Store", "Category", "Sub
Category","SEGMENT1", "Material Number", "Model Name"}, {{"Sell Out QTY", each List.Sum([Sell Out QTY]), type
number}, {"Sell Out AMT", each List.Sum([Sell Out AMT]), type number}, {"Channel Inv", each List.Sum([Channel
Inv]), type number}, {"Ranging", each List.Sum([Ranging]), type number}})

in

#"Grouped Rows"

SS_Payers
let

Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],

#"Changed Type" = Table.TransformColumnTypes(Source,{{"Point of Sales", type text}, {"Payer Code", type text}})

in

#"Changed Type"

MM

let

Source = Excel.CurrentWorkbook(){[Name="MONTH"]}[Content],

#"Changed Type" = Table.TransformColumnTypes(Source,{{"MM", type text}})

in

#"Changed Type"

#"Replaced Value" = Table.ReplaceValue(#"Changed Type","#SRLA","80001",Replacer.ReplaceText,{"Payer


Code"}),

#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","#WS","#",Replacer.ReplaceText,{"Payer Code"}),

ROLLING_FCT_SUMMARY
let
actmonth = if fnGetParameter("ACT_MTH")=null then 0 else Date.Month(Date.AddMonths(Date.FromText("1-"&
fnGetParameter("ACT_MTH")),-3)),
event = "FY"&Text.End(Text.From(fnGetParameter("CUR_FY")),2)&" "& Text.From(Date.Month( Date.FromText("1-"&
fnGetParameter("FCT_MTH")) )) &"F",
Path = fnGetParameter("FCT_PATH"), UseSrlaFct = (fnGetParameter("SRLAFCT_SRC") = "SRLA"), Origen = Folder.Files(Path & "\1. Rolling
Forecast"),
SelectRows0 = Table.SelectRows(Origen, each ([Extension] = ".xlsm") and (not Text.Contains([Name], "~$"))),
SelectColumns0 = Table.SelectColumns(SelectRows0,{"Content"}),
AddColumn0 = Table.AddColumn(SelectColumns0, "GetExcelData", each Excel.Workbook([Content])),
RemoveColumns0 = Table.RemoveColumns(AddColumn0,{"Content"}),
ExpandTableColumn0 = Table.ExpandTableColumn(RemoveColumns0, "GetExcelData", {"Name", "Data"}, {"Name", "Data"}),
SelectRows2 = Table.SelectRows(ExpandTableColumn0, each ([Name] = "PSIRANGE2")),
AddColumn2 = Table.AddColumn(SelectRows2, "PromoteHeader", each Table.PromoteHeaders([Data])),
SelectColumns2 = Table.SelectColumns(AddColumn2,{"PromoteHeader"}),
ExpandTableColumn2 = Table.ExpandTableColumn(SelectColumns2, "PromoteHeader",
{"DEALER","PAYER CODE","CATEGORY","SUB CATEGORY","SKU","8D CODE","MODEL
NAME","SERIES","EVENT","ITEM","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC","JAN","FEB","MAR"},
{"Dealer","Payer Code","Category","Sub Category","SKU","8D Code","Model
Name","SERIES","FY" ,"ITEM","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC","JAN","FEB","MAR"}),
SelectRows3 = Table.SelectRows(ExpandTableColumn2, each [FY] = event and [Dealer] <> "SOLA" and ([ITEM] = "Channel Inv" or [ITEM] =
"Ranging" or [ITEM] = "Sell out AMT" or [ITEM] = "Sell Out QTY")),
UnpivotOtherColumns0 = Table.UnpivotOtherColumns(SelectRows3,
{"Dealer","Payer Code","Category","Sub Category","SKU","8D Code","Model Name","SERIES","FY" ,"ITEM"}, "Month", "Value"),
TransformColumnTypes0 = Table.TransformColumnTypes(UnpivotOtherColumns0,{{"Payer Code", type text},{"8D Code", type text},
{"Month", type text},{"Value", type number}}),
AddColumn3 = Table.AddColumn(TransformColumnTypes0, "MTH_NUM", each
Date.Month(Date.AddMonths(Date.FromText("1-"&[Month]),-3))),
SelectRows4 = Table.SelectRows(AddColumn3, each [MTH_NUM] > actmonth and [Value]<>null and [Value]<>0),
Pivot0 = Table.Pivot(SelectRows4, List.Distinct(SelectRows4[ITEM]), "ITEM", "Value", List.Sum),
RenameColumns0 = Table.RenameColumns(Pivot0,{{"Channel Inv", "Inventory QTY"}, {"Sell out AMT", "Sell Out AMT"}}),
MergedQueries0 = Table.NestedJoin(RenameColumns0,{"Payer Code"},DEALER_MASTER,{"Payer Code"},"NewColumn",JoinKind.LeftOuter),
RemoveColumns2 = Table.RemoveColumns(MergedQueries0,{"Dealer", "Payer Code","MTH_NUM"}),
ExpandTableColumn3 = Table.ExpandTableColumn(RemoveColumns2, "NewColumn",
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name", "Payer Code"},
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name", "Payer Code"}),
RMNULL = Table.ReplaceValue(ExpandTableColumn3,null,0,Replacer.ReplaceValue,{"Sell Out QTY", "Sell Out AMT", "Inventory QTY"})
in
RMNULL

ACT_DM
let
weeks_inv = List.RemoveMatchingItems(List.Distinct(Text.SplitAny( fnGetParameter("WEEKS_INV") , "','")),{""}),
Actmonth = if fnGetParameter("ACT_MTH")=null then 0 else Date.Month(Date.AddMonths(Date.FromText("1-"&
fnGetParameter("ACT_MTH")),-3)),
CurrFY = "FY" & Text.End(Text.From(fnGetParameter("CUR_FY")),2),
Path = "C:\RobotWorkspace\01. Projects\SPU\ElCondor\ACT\FY_SELLOUT",
Source = Folder.Files(Path),
SelectRows0 = Table.SelectRows(Source, each [Extension] = ".xlsm" and (not Text.Contains([Name], "~$")) and Text.Start([Name],4) =
CurrFY),
AddColumn0 = Table.AddColumn(SelectRows0, "Custom", each Excel.Workbook([Content])),
ExpandTableColumn0 = Table.ExpandTableColumn(AddColumn0, "Custom", {"Name", "Data", "Item", "Kind", "Hidden"}, {"Custom.Name",
"Custom.Data", "Custom.Item", "Custom.Kind", "Custom.Hidden"}),
SelectRows1 = Table.SelectRows(ExpandTableColumn0, each ([Custom.Item] = "DF_GRID_1")),
AddColumn1 = Table.AddColumn(SelectRows1, "Custom", each Table.PromoteHeaders([Custom.Data])),
SelectColumns0 = Table.SelectColumns(AddColumn1,{"Custom"}),
ExpandTableColumn1 = Table.ExpandTableColumn(SelectColumns0, "Custom",
{"Calendar year / week","Calendar Year/Month","Payer" ,"" ,"Point of Sales","_1" ,"Material group","_2" ,"Material
Number","Key Figures","#(lf)Sell-Out Qty","#(lf)Dealear Stock Qty","#(lf)Sell-Out Amt"},
{"CalendarYearWeek", "MMYYYY" ,"Payer Code","Dealer","Point of Sales","Store Code","6D Code" ,"Category","8D
Code" ,"Model Name" ,"Sell Out QTY" ,"Inventory QTY" ,"Sell Out AMT"}),
ReplaceValue0 = Table.ReplaceValue(ExpandTableColumn1, each [Inventory QTY], each if List.Contains(weeks_inv,[CalendarYearWeek])
then [Inventory QTY] else 0,Replacer.ReplaceValue,{"Inventory QTY"}),
ReplaceValue1 = Table.ReplaceValue(ReplaceValue0, each [Payer Code], each if Text.Contains([Point of Sales],"PARIS") then "66666" else
[Payer Code],Replacer.ReplaceValue,{"Payer Code"}),
ReplaceValue2 = Table.ReplaceValue(ReplaceValue1,null,0,Replacer.ReplaceValue,{"Sell Out QTY","Inventory QTY","Sell Out AMT"}),
SelectRows2 = Table.SelectRows(ReplaceValue2, each [MMYYYY] <> "Result" and [Dealer] <> "Sony Store - OFFLINE" and [Dealer] <> "Sony
Store - ONLINE"),
GroupedRows0 = Table.Group(SelectRows2,
{"MMYYYY","Payer Code","Dealer", "Point of Sales","Store Code","6D Code","Category","8D Code","Model Name"},
{{"Sell Out QTY", each List.Sum([Sell Out QTY]), type number},{"Inventory QTY", each List.Sum([Inventory QTY]), type number},{"Sell Out
AMT", each List.Sum([Sell Out AMT]), type number}}),
SplitColumn0 = Table.SplitColumn(GroupedRows0,"MMYYYY",Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv),{"MonthNumber", "CY"}),
TransformColumnTypes0 = Table.TransformColumnTypes(SplitColumn0,{{"MonthNumber",Int64.Type},{"CY",Int64.Type},{"Sell Out
QTY",type number},{"Sell Out AMT",type number}, {"Inventory QTY", type number}}),
AddColumn2 = Table.AddColumn(TransformColumnTypes0, "FY", each CurrFY),
AddColumn3 = Table.AddColumn(AddColumn2, "Month", each Text.Upper(Date.ToText(#date([CY],[MonthNumber],1),"MMM"))),
SelectRows3 = Table.SelectRows(AddColumn3, each (Date.Month(Date.AddMonths(Date.FromText("1-" & [Month], "En-US"),-3)) <=
Actmonth)),
RemoveColumns0 = Table.RemoveColumns(SelectRows3,{"MonthNumber", "CY"}),
AddColumn4 = Table.AddColumn(RemoveColumns0, "Ranging", each if ([Inventory QTY]+[Sell Out QTY]>0) then 1 else 0),
GroupStoresbyDealer = Table.Group(AddColumn4, {"Payer Code","Category", "8D Code", "Model Name", "FY", "Month"}, {
{"Sell Out AMT", each List.Sum([Sell Out AMT]), type number},{"Sell Out QTY", each List.Sum([Sell Out QTY]), type number},
{"Inventory QTY", each List.Sum([Inventory QTY]), type number},{"Ranging", each List.Sum([Ranging]), type number}}),
MergedQueries0 = Table.NestedJoin(GroupStoresbyDealer,{"Payer Code"},DEALER_MASTER,{"Payer
Code"},"NewColumn",JoinKind.LeftOuter),
ExpandTableColumn2 = Table.ExpandTableColumn(MergedQueries0, "NewColumn",
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"},
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"}),

AddColumn5 = Table.AddColumn(ExpandTableColumn2, "FYMM", each "20" & Text.End([FY],2) &


Number.ToText(Date.Month(Date.FromText("1-"& [Month])),"00")),
TransformColumns0 = Table.TransformColumns(AddColumn5, {{"FY", each _ & " " & Text.From(Date.Month(Date.FromText("1-"&
fnGetParameter("FCT_MTH")))) & "F" , type text}}),
TransformColumns1 = Table.TransformColumns(TransformColumns0 , {{"8D Code", each try Number.ToText(Number.From(_),"00000000")
otherwise _ , type text}}),
ReorderColumns0 = Table.ReorderColumns(TransformColumns1,{"Payer Code", "Category", "8D Code", "Model Name", "FY", "Month",
"Ranging", "Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name", "Sell Out
QTY", "Inventory QTY", "Sell Out AMT"}),
SelectRows4 = Table.SelectRows(ReorderColumns0, each [Inventory QTY]+[Sell Out QTY]+[Sell Out AMT]>0 ),
Combine0 = Table.Combine({SelectRows4, #"EV BUNDLE"})
in
Combine0
ACT_SS

let
ActMonth = if fnGetParameter("ACT_MTH")=null then 0 else Date.Month(Date.AddMonths(Date.FromText("1-"&
fnGetParameter("ACT_MTH")),-3)),
event = "FY"&Text.End(Text.From(fnGetParameter("CUR_FY")),2)&" "& Text.From(Date.Month( Date.FromText("1-"&
fnGetParameter("FCT_MTH")) )) &"F",
Source = Folder.Files("C:\RobotWorkspace\01. Projects\SPU\ElCondor\ACT\TRIPLE_QUERIES"),
SelectRows0 = Table.SelectRows(Source, each [Name] <> ".cekey" and not Text.Contains([Name], "~$") and not Text.Contains([Name],
"_CL30") and Text.Contains([Name], Text.End(Text.From(fnGetParameter("CUR_FY")),2)) ),
SelectColumns0 = Table.SelectColumns(SelectRows0,{"Content"}),
AddColumn0 = Table.AddColumn(SelectColumns0, "Custom", each Excel.Workbook([Content])),
ExpandTableColumn0 = Table.ExpandTableColumn(AddColumn0, "Custom", {"Data", "Item"}, {"Custom.Data", "Custom.Item"}),
SelectRows1 = Table.SelectRows(ExpandTableColumn0, each ([Custom.Item] = "DF_GRID_1")),
AddColumn1 = Table.AddColumn(SelectRows1, "ExclHeaders", each Table.PromoteHeaders(Table.PromoteHeaders([Custom.Data]))),
RemoveColumns0 = Table.RemoveColumns(AddColumn1,{"Custom.Item","Content", "Custom.Data"}),
ExpandTableColumn1 = Table.ExpandTableColumn(RemoveColumns0, "ExclHeaders",
{"Fiscal Period","Payer" ,"_1" ,"Material Number","_2" ,"Ship-to Party","Outside Sales & Operating Revenue", "Outside Sales &
Operating Revenue_9"},
{"Month" ,"Payer Code","Category","8D Code" ,"Model Name" ,"Ship" , "Sell Out AMT" , "Sell Out QTY"}),
SelectRows2 = Table.SelectRows(ExpandTableColumn1, each (Date.Month(Date.AddMonths(Date.FromText("1-" & [Month], "En-US"),-3)) <=
ActMonth)),
ReplaceValue0 = Table.ReplaceValue(SelectRows2, each [Payer Code], each if [Ship]="D07004748" then "66666" else [Payer
Code],Replacer.ReplaceValue,{"Payer Code"}),
ReplaceValue1 = Table.ReplaceValue(ReplaceValue0, each [Payer Code], each if List.Contains(DEALER_MASTER[Payer Code], [Payer Code])
then [Payer Code] else "#",Replacer.ReplaceValue,{"Payer Code"}),
RemoveColumns1 = Table.RemoveColumns(ReplaceValue1,{"Ship"}),
ReplaceValue2 = Table.ReplaceValue(RemoveColumns1,null,0,Replacer.ReplaceValue,{"Sell Out AMT","Sell Out QTY"}),
TransformColumns1 = Table.TransformColumns(ReplaceValue2 , {{"8D Code", each try Number.ToText(Number.From(_),"00000000")
otherwise _ , type text},{"Sell Out AMT", each _ * 100, type number}}),
Group0 = Table.Group(TransformColumns1,
{"Month","Payer Code","Category","8D Code","Model Name"},
{{"Sell Out AMT", each List.Sum([Sell Out AMT]), type number}, {"Sell Out QTY", each List.Sum([Sell Out QTY]), type number}}),
MergedQueries0 = Table.NestedJoin(Group0,{"Payer Code"},DEALER_MASTER,{"Payer Code"},"NewColumn",JoinKind.LeftOuter),
ExpandTableColumn2= Table.ExpandTableColumn(MergedQueries0, "NewColumn",
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"},
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"}),
SelectRows3 = Table.SelectRows(ExpandTableColumn2, each ([Sell Out QTY] <> 0) and ([Koro Name] = "CHANCAFE" or [Koro Name] =
"COUNTRY" or [Koro Name] = "E-COMMERCE" or [Koro Name] = "JOCKEY PLAZA" or [Koro Name] = "SIMA" or [Koro Name] = "SONY RETAIL")),
AddColumn2 = Table.AddColumn(SelectRows3, "Inventory QTY", each 0),
AddColumn3 = Table.AddColumn(AddColumn2, "Ranging", each 1),
AddColumn4 = Table.AddColumn(AddColumn3, "FY", each event),
ReorderColumns0 = Table.ReorderColumns(AddColumn4,{"Payer Code", "Category", "8D Code", "Model Name", "FY", "Month",
"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name", "Sell Out QTY","Sell
Out AMT"})
in
ReorderColumns0

EV_BUNDLE

let
weeks_inv = List.RemoveMatchingItems(List.Distinct(Text.SplitAny( fnGetParameter("WEEKS_INV") , "','")),{""}),
Actmonth = if fnGetParameter("ACT_MTH")=null then 0 else Date.Month(Date.AddMonths(Date.FromText("1-"&
fnGetParameter("ACT_MTH")),-3)),
CurrFY = "FY" & Text.End(Text.From(fnGetParameter("CUR_FY")),2),
Path = "C:\RobotWorkspace\01. Projects\SPU\ElCondor\ACT\FY_SELLOUT",
Source = Folder.Files(Path),
SelectRows0 = Table.SelectRows(Source, each [Extension] = ".xlsm" and (not Text.Contains([Name], "~$")) and Text.Start([Name],4) =
CurrFY),
AddColumn0 = Table.AddColumn(SelectRows0, "Custom", each Excel.Workbook([Content])),
ExpandTableColumn0 = Table.ExpandTableColumn(AddColumn0, "Custom", {"Name", "Data", "Item", "Kind", "Hidden"}, {"Custom.Name",
"Custom.Data", "Custom.Item", "Custom.Kind", "Custom.Hidden"}),
SelectRows1 = Table.SelectRows(ExpandTableColumn0, each ([Custom.Item] = "DF_GRID_1")),
AddColumn1 = Table.AddColumn(SelectRows1, "Custom", each Table.PromoteHeaders([Custom.Data])),
SelectColumns0 = Table.SelectColumns(AddColumn1,{"Custom"}),
ExpandTableColumn1 = Table.ExpandTableColumn(SelectColumns0, "Custom",
{"Calendar year / week","Calendar Year/Month","Payer" ,"" ,"Point of Sales","_1" ,"Material group","_2" ,"Material
Number","Key Figures","#(lf)Sell-Out Qty","#(lf)Dealear Stock Qty","#(lf)Sell-Out Amt"},
{"CalendarYearWeek", "MMYYYY" ,"Payer Code","Dealer","Point of Sales","Store Code","6D Code" ,"Category","8D
Code" ,"Model Name" ,"Sell Out QTY" ,"Inventory QTY" ,"Sell Out AMT"}),
ReplaceValue0 = Table.ReplaceValue(ExpandTableColumn1, each [Inventory QTY], each if List.Contains(weeks_inv,[CalendarYearWeek])
then [Inventory QTY] else 0,Replacer.ReplaceValue,{"Inventory QTY"}),

SelectRowsEV = Table.SelectRows(ReplaceValue0, each ([Dealer] = "CONECTA RETAIL S.A." or [Dealer] = "ELECTROTIENDAS DEL PERU S.A.C."
or [Dealer] = "GMG COMERCIAL PERU S.A") and ([Category] = "CAR AFTER")),
RemoveColumnsEV = Table.RemoveColumns(SelectRowsEV,{"Dealer"}),
MergedQueriesEV = Table.NestedJoin(RemoveColumnsEV,{"Payer Code"},DEALER_MASTER,{"Payer
Code"},"DEALER_MASTER",JoinKind.LeftOuter),
ExpandTableColumnEV = Table.ExpandTableColumn(MergedQueriesEV, "DEALER_MASTER", {"Dealer"}, {"Dealer"}),
MergedQueriesEV2 = Table.NestedJoin(ExpandTableColumnEV,{"8D Code", "Dealer"},BUNDLE,{"MU_8D CODE",
"DEALER"},"NewColumn",JoinKind.Inner),
ExpandTableColumnEV2 = Table.ExpandTableColumn(MergedQueriesEV2, "NewColumn", {"CODE1", "MODEL1"}, {"CODE1", "MODEL1"}),
RemoveColumnsEV2 = Table.RemoveColumns(ExpandTableColumnEV2,{"8D Code","Model Name"}),
RenameColumnsEV = Table.RenameColumns(RemoveColumnsEV2,{{"CODE1", "8D Code"},{"MODEL1", "Model Name"}}),

ReplaceValue2 = Table.ReplaceValue(RenameColumnsEV,null,0,Replacer.ReplaceValue,{"Sell Out QTY","Inventory QTY","Sell Out AMT"}),


GroupedRows0 = Table.Group(ReplaceValue2,
{"MMYYYY","Payer Code","Dealer", "Point of Sales","Store Code","6D Code","Category","8D Code","Model Name"},
{{"Sell Out QTY", each List.Sum([Sell Out QTY]), type number},{"Inventory QTY", each List.Sum([Inventory QTY]), type number},{"Sell Out
AMT", each List.Sum([Sell Out AMT]), type number}}),
SplitColumn0 = Table.SplitColumn(GroupedRows0,"MMYYYY",Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv),{"MonthNumber", "CY"}),
TransformColumnTypes0 = Table.TransformColumnTypes(SplitColumn0,{{"MonthNumber",Int64.Type},{"CY",Int64.Type},{"Sell Out
QTY",type number},{"Sell Out AMT",type number}, {"Inventory QTY", type number}}),
AddColumn2 = Table.AddColumn(TransformColumnTypes0, "FY", each CurrFY),
AddColumn3 = Table.AddColumn(AddColumn2, "Month", each Text.Upper(Date.ToText(#date([CY],[MonthNumber],1),"MMM"))),
SelectRows3 = Table.SelectRows(AddColumn3, each (Date.Month(Date.AddMonths(Date.FromText("1-" & [Month], "En-US"),-3)) <=
Actmonth)),
RemoveColumns0 = Table.RemoveColumns(SelectRows3,{"MonthNumber", "CY"}),
AddColumn4 = Table.AddColumn(RemoveColumns0, "Ranging", each if ([Inventory QTY]+[Sell Out QTY]>0) then 1 else 0),
GroupStoresbyDealer = Table.Group(AddColumn4, {"Payer Code","Category", "8D Code", "Model Name", "FY", "Month"}, {
{"Sell Out AMT", each List.Sum([Sell Out AMT]), type number},{"Sell Out QTY", each List.Sum([Sell Out QTY]), type number},
{"Inventory QTY", each List.Sum([Inventory QTY]), type number},{"Ranging", each List.Sum([Ranging]), type number}}),
MergedQueries0 = Table.NestedJoin(GroupStoresbyDealer,{"Payer Code"},DEALER_MASTER,{"Payer
Code"},"NewColumn",JoinKind.LeftOuter),
ExpandTableColumn2 = Table.ExpandTableColumn(MergedQueries0, "NewColumn",
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"},
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"}),
AddColumn5 = Table.AddColumn(ExpandTableColumn2, "FYMM", each "20" & Text.End([FY],2) &
Number.ToText(Date.Month(Date.FromText("1-"& [Month])),"00")),
TransformColumns0 = Table.TransformColumns(AddColumn5, {{"FY", each _ & " " & Text.From(Date.Month(Date.FromText("1-"&
fnGetParameter("FCT_MTH")))) & "F" , type text}}),
TransformColumns1 = Table.TransformColumns(TransformColumns0 , {{"8D Code", each try Number.ToText(Number.From(_),"00000000")
otherwise _ , type text}}),
ReorderColumns0 = Table.ReorderColumns(TransformColumns1,{"Payer Code", "Category", "8D Code", "Model Name", "FY", "Month",
"Ranging", "Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name", "Sell Out
QTY", "Inventory QTY", "Sell Out AMT"})
in
ReorderColumns0

"Category", "Sub Category", "SKU", "Model Name", "SERIES"}),

ExpandTableColumn3 = Table.ExpandTableColumn(RemoveColumns2, "NewColumn",


{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name", "Payer Code"},
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name", "Payer Code"}),
ExpandTableColumn2 = Table.ExpandTableColumn(MergedQueries0, "NewColumn",
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"},
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"}),

ExpandTableColumn2= Table.ExpandTableColumn(MergedQueries0, "NewColumn",


{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"},
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"}),
ExpandTableColumn2 = Table.ExpandTableColumn(MergedQueries0, "NewColumn",
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"},
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"}),
ExpandTableColumn2 = Table.ExpandTableColumn(MergedQueries0, "NewColumn",
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"},
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name"}),
ExpandTableColumn3 = Table.ExpandTableColumn(RemoveColumns2, "NewColumn",
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name", "Payer Code"},
{"Country", "Company", "Channel Group", "Channel", "Dealer Group", "Dealer", "Koro Name", "Store", "Payer Name", "Payer Code"}),

You might also like