Purpose: To make decision on stocking decision of product, we will first look into usage at the product level and classify the product into couple of groups.
Deta: Annual Demand at the product-location level.
Steps
1. Aggregate Demand into Product Level View
2. Rank Product by Demand at the descending order
3. Calculate Percent of Total Demand
4. Calculate Running Total and Running Total %
Deta: Annual Demand at the product-location level.
SELECT A.[Product ID], A.Demand Demand_Location_1, B.Demand Demand_Location_2, C.Demand Demand_Location_3, D.Demand Demand_Location_4, E.Demand Demand_Location_5 FROM (Select * from [Simulation].[001_Product_Loc_Demand] Where [Location ID] = 1 ) A Inner join (Select * from [Simulation].[001_Product_Loc_Demand] Where [Location ID] = 2 ) B On A.[Product ID] = B.[Product ID] Inner join (Select * from [Simulation].[001_Product_Loc_Demand] Where [Location ID] = 3 ) C On A.[Product ID] = C.[Product ID] Inner join (Select * from [Simulation].[001_Product_Loc_Demand] Where [Location ID] = 4 ) D On A.[Product ID] = D.[Product ID] Inner join (Select * from [Simulation].[001_Product_Loc_Demand] Where [Location ID] = 5 ) E On A.[Product ID] = E.[Product ID];
Steps
1. Aggregate Demand into Product Level View
Create View [Simulation].[View_001_Aggregate_Demandl] As Select [Product ID], Sum(Demand) Aggregate_Demand from [Simulation].[001_Product_Loc_Demand] Group by [Product ID]
2. Rank Product by Demand at the descending order
Create View [Simulation].[View_002_Ranking] As SELECT [Product ID], Aggregate_Demand, ROW_NUMBER() OVER (ORDER BY Aggregate_Demand DESC) AS [Rank] FROM [Simulation].[View_001_Aggregate_Demand]
3. Calculate Percent of Total Demand
Create View [Simulation].[View_003_%_Of_Total] As select [Product ID], [Aggregate_Demand], [Rank], Sum([Aggregate_Demand]) OVER () Total_Demand, Cast(Cast([Aggregate_Demand] as numeric(9,2))/ cast(Sum([Aggregate_Demand]) OVER () as numeric(9,2)) as numeric(9,2)) As [%_Of_Total] from [Simulation].[View_002_Ranking]
4. Calculate Running Total and Running Total %
Create View [Simulation].[View_004_Running_Total] As select [Product ID], [Aggregate_Demand], [Rank], Total_Demand, [%_Of_Total], Sum([Aggregate_Demand]) OVER (ORDER BY [Aggregate_Demand] DESC Rows BETWEEN unbounded preceding AND CURRENT row) [Running_Total], CAST(Sum([Aggregate_Demand]) OVER (ORDER BY [Aggregate_Demand] DESC Rows BETWEEN unbounded preceding AND CURRENT row) AS numeric(9,2))/ CAST(Total_Demand AS numeric(9,2)) [Running_Total_%] from [Simulation].[View_003_%_Of_Total]
Comments
Post a Comment