Automatizando Consolidated So
Automatizando Consolidated So
Automatizando Consolidated So
let
Path = fnGetParameter("FCT_PATH"),
{"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"}),
#"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"),
#"Filtered Rows7" = Table.SelectRows(#"Changed Type1", each ([ITEM] = "Channel Inv" or [ITEM] = "Ranging" or
[ITEM] = "Sell out AMT" or [ITEM] = "Sell Out QTY")),
RMNONACTIVE = Table.SelectRows(RMNULL, each (([#"Inventory QTY"]+[#"Sell Out QTY"]+[#"Sell Out AMT"]) <>
0)),
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
Source = Folder.Files(Path),
#"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}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Payer Name] <> "Sony Store - OFFLINE" and [Payer
Name] <> "Sony Store - ONLINE")),
GroupStoresbyDealer = Table.Group( #"Added Custom2", {"Payer Code","6D Code", "Category", "8D Code",
"Model Name", "FY", "Month"}, {
#"Extracted First Characters" = Table.TransformColumns(#"Removed Columns2", {{"FY", each _ & " " &
Text.From(Date.Month(Date.FromText("1-"& fnGetParameter("FCT_MTH")))) & "F" , type text}}),
#"Appended Query"
ACT_SS
let
#"Filtered Rows2" = Table.SelectRows(Source, each ([Name] <> ".cekey" and not Text.Contains([Name], "~$") and
not Text.Contains([Name], "_CL30"))),
/* 8D Code adjustment: Set 8 Digits for all numerical codes (e.g. 123456->00123456, R123456->R123456) */
#"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
*/
/* Dealer Categorization: Add dealer fields from payer code. *Set #(Not Assigned) for all non Key Dealers for
grouping purpose*/
#"Multiplied Column" = Table.TransformColumns(#"Filtered Rows4", {{"Sell Out AMT", each _ * 100, type
number}})
in
#"Multiplied Column"
EV BUNDLE
let
Source = Folder.Files(Path),
#"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")),
#"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}}),
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},
#"Extracted First Characters" = Table.TransformColumns(#"Removed Columns2", {{"FY", each _ & " " &
Text.From(Date.Month(Date.FromText("1-"& fnGetParameter("FCT_MTH")))) & "F" , type text}}),
in
#"Reordered Columns"
DEALER_MASTER
let
#"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each ([Payer Code] <> "Not Used")),
in
#"Changed Type1"
CLUSTER_MASTER
let
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
Hoja1_Sheet = Source{[Item="Categorization",Kind="Table"]}[Data],
in
#"Changed Type1"
FCT_CONSOLIDATED_ADJ
let
Source = #"WEEKLY_SELLOUT",
in
#"Reordered Columns1"
WEEKLY_SELLOUT
/*
let
in
#"Changed Type"
*/
let
#"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")),
#"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
Source = Excel.CurrentWorkbook(){[Name="SPLIT"]}[Content],
#"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}}),
#"FY"= Table.TransformColumns(#"Filtered Rows1", {{"FISCAL YEAR", each _ & " " & Number.ToText(actmonth) &
"F" , type text}})
in
#"FY"
FCT_CONSOLIDATED
let
#"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],
in
#"Changed Type"
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"}),
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"}}),