Martinl
New member
- Joined
- Dec 2, 2016
- Messages
- 15
- Reaction score
- 0
- Points
- 0
- Excel Version(s)
- 2016 MSO (16.0.9126.2259)
I have a 1 hour wait for the the following code which looks a spreadsheet on SharePoint
the Spreadsheet is filtered for the latest 2 months and then referenced twice to create a query of last months data and the previous months data
these two are then merged with a full outer join into this 4th Query.
Is there a quicker way to accomplish this.
Queries 1-3 take about 3 mins each to run and all are connection only queries
Query 4 is output as a pivot table in Excel but at over a hour to refresh I may have to pull the plug and think of something else.
this is the Query 4 code
the Spreadsheet is filtered for the latest 2 months and then referenced twice to create a query of last months data and the previous months data
these two are then merged with a full outer join into this 4th Query.
Is there a quicker way to accomplish this.
Queries 1-3 take about 3 mins each to run and all are connection only queries
Query 4 is output as a pivot table in Excel but at over a hour to refresh I may have to pull the plug and think of something else.
this is the Query 4 code
Code:
let
Source = Table.NestedJoin(#"Last Month",{"Material Number", "PC Number"},#"Previous Month",{"Material Number", "PC Number"},"Previous Month",JoinKind.FullOuter),
#"Expanded Previous Month" = Table.ExpandTableColumn(Source, "Previous Month", {"FY", "Month", "Material Name - Property -", "Model", "Material Number", "Family", "Multipack?", "Multipack", "Material Sub Business Unit", "MPG Name", "MPG Brief Description", "Profit Center", "Direct Region", "Territory", "Direct Customer Classification", "PC Number", "Direct Customer", "Indirect Region", "Sell in", "Sell Out", "SAL Coverage %", "Stock", "Stock Coverage%", "Sell in Multipack", "Sell out Multipack", "Stock Multipack", "Sell out EUR", "Source", "Data"}, {"Previous Month.FY", "Previous Month.Month", "Previous Month.Material Name - Property -", "Previous Month.Model", "Previous Month.Material Number", "Previous Month.Family", "Previous Month.Multipack?", "Previous Month.Multipack", "Previous Month.Material Sub Business Unit", "Previous Month.MPG Name", "Previous Month.MPG Brief Description", "Previous Month.Profit Center", "Previous Month.Direct Region", "Previous Month.Territory", "Previous Month.Direct Customer Classification", "Previous Month.PC Number", "Previous Month.Direct Customer", "Previous Month.Indirect Region", "Previous Month.Sell in", "Previous Month.Sell Out", "Previous Month.SAL Coverage %", "Previous Month.Stock", "Previous Month.Stock Coverage%", "Previous Month.Sell in Multipack", "Previous Month.Sell out Multipack", "Previous Month.Stock Multipack", "Previous Month.Sell out EUR", "Previous Month.Source", "Previous Month.Data"}),
FY = Table.AddColumn(#"Expanded Previous Month", "FY1", each if [FY] = null then [Previous Month.FY] else [FY] ),
Month = Table.AddColumn(FY, "Month1", each if [Month] = null then [Previous Month.Month] else [Month] ),
#"Material Name" = Table.AddColumn(Month, "Material Name", each if [FY] = null then [Previous Month.FY] else [#"Material Name - Property -"] ),
Model = Table.AddColumn(#"Material Name", "Model1", each if [Model] = null then [Previous Month.Model] else [Model] ),
#"Material Number" = Table.AddColumn(Model, "Material Number1", each if [Material Number] = null then [Previous Month.Material Number] else [Material Number] ),
Family = Table.AddColumn(#"Material Number", "Family1", each if [Family] = null then [Previous Month.Family] else [Family] ),
#"Multipack?" = Table.AddColumn(Family, "Custom", each if [#"Multipack?"] = null then [#"Previous Month.Multipack?"] else [#"Multipack?"]),
Multipack = Table.AddColumn(#"Multipack?", "Multipack1", each if [Multipack] = null then [Previous Month.Multipack] else [Multipack] ),
#"Material Sub Business Unit" = Table.AddColumn(Multipack, "Material Sub Business Unit1", each if [Material Sub Business Unit] = null then [Previous Month.Material Sub Business Unit] else [Material Sub Business Unit] ),
#"MPG Name" = Table.AddColumn(#"Material Sub Business Unit", "MPG Name1", each if [MPG Name] = null then [Previous Month.MPG Name] else [MPG Name] ),
#"MPG Brief Description" = Table.AddColumn(#"MPG Name", "MPG Brief Description1", each if [MPG Brief Description] = null then [Previous Month.MPG Brief Description] else [MPG Brief Description] ),
#"Profit Center" = Table.AddColumn(#"MPG Brief Description", "Profit Center1", each if [Profit Center] = null then [Previous Month.Profit Center] else [Profit Center] ),
Region = Table.AddColumn(#"Profit Center", "Region", each if [Direct Region] = null then [Previous Month.Direct Region] else [Direct Region] ),
Territory = Table.AddColumn(Region, "Territory1", each if [Territory] = "" then [Previous Month.Territory] else [Territory]),
#"Cust Class" = Table.AddColumn(Territory, "Customer Classification", each if [Direct Customer Classification] = null then [Previous Month.Direct Customer Classification] else [Direct Customer Classification] ),
#"PC Number" = Table.AddColumn(#"Cust Class", "PC Number1", each if [PC Number] = null then [Previous Month.PC Number] else [PC Number] ),
Customer = Table.AddColumn(#"PC Number", "Customer1", each if [Direct Customer] = null then [Previous Month.Direct Customer] else [Direct Customer] ),
#"Indirect Region" = Table.AddColumn(Customer, "Indirect Region1", each if [Indirect Region] = null then [Previous Month.Indirect Region] else [Indirect Region] ),
Source1 = Table.AddColumn(#"Indirect Region", "Source1", each if [Source] = null then [Previous Month.Source] else [Source] ),
Data = Table.AddColumn(Source1, "Data1", each if [Data] = null then [Previous Month.Data] else [Data] ),
#"Removed Other Columns" = Table.SelectColumns(Data,{"Month1", "Material Name", "Model1", "Material Number1", "Family1", "Custom", "Multipack1", "Material Sub Business Unit1", "MPG Name1", "MPG Brief Description1", "Profit Center1", "Region", "Territory1", "Customer Classification", "PC Number1", "Customer1", "Indirect Region1", "Source1", "Data1", "Sell in", "Sell Out", "SAL Coverage %", "Stock", "Stock Coverage%", "Sell in Multipack", "Sell out Multipack", "Stock Multipack", "Sell out EUR", "Previous Month.Sell in", "Previous Month.Sell Out", "Previous Month.SAL Coverage %", "Previous Month.Stock", "Previous Month.Stock Coverage%", "Previous Month.Sell in Multipack", "Previous Month.Sell out Multipack", "Previous Month.Stock Multipack", "Previous Month.Sell out EUR"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"Month1", "Month"}, {"Model1", "Model"}, {"Material Number1", "Material Number"}, {"Family1", "Family"}, {"Multipack1", "Multipack"}, {"Material Sub Business Unit1", "Material Sub Business Unit"}, {"MPG Name1", "MPG Name"}, {"MPG Brief Description1", "MPG Brief Description"}, {"Profit Center1", "Profit Center"}, {"Territory1", "Territory"}, {"PC Number1", "PC Number"}, {"Customer1", "Customer"}, {"Indirect Region1", "Indirect Region"}, {"Source1", "Source"}, {"Data1", "Data"}, {"Sell in", "Last Month.Sell in"}, {"Sell Out", "Last Month.Sell Out"}, {"SAL Coverage %", "Last Month.SAL Coverage %"}, {"Stock", "Last Month.Stock"}, {"Stock Coverage%", "Last Month.Stock Coverage%"}, {"Sell in Multipack", "Last Month.Sell in Multipack"}, {"Sell out Multipack", "Last Month.Sell out Multipack"}, {"Stock Multipack", "Last Month.Stock Multipack"}, {"Sell out EUR", "Last Month.Sell out EUR"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Month", type date}, {"Material Name", type text}, {"Model", type text}, {"Material Number", type text}, {"Family", type text}, {"Custom", type text}, {"Multipack", type text}, {"Material Sub Business Unit", type text}, {"MPG Name", type text}, {"MPG Brief Description", type text}, {"Profit Center", type text}, {"Region", type text}, {"Territory", type text}, {"Customer Classification", type text}, {"PC Number", type text}, {"Customer", type text}, {"Indirect Region", type text}, {"Source", type text}, {"Data", type text}}),
#"LM.StoMP(Calc)" = Table.AddColumn(#"Changed Type", "Last Month.Stock Multipack (Calculated)", each [Previous Month.Stock Multipack]+[Previous Month.Sell in Multipack]-[Last Month.Sell Out]),
#"ABS.Difference" = Table.AddColumn(#"LM.StoMP(Calc)", "Difference (Reported - Calculated)", each Number.Abs([Last Month.Stock Multipack]-[#"Last Month.Stock Multipack (Calculated)"]))
in
#"ABS.Difference"