This function allows to split a Demand (for ex.: Sales Forecasts) from monthly into weekly buckets.
We need a dataset with the 3 variables to use this function :
a Product: it’s an item, a SKU (Storage Keeping Unit), or a SKU at a location, also called a DFU (Demand Forecast Unit)
a Period of time : here in monthly buckets
a Demand : could be some sales forecasts, expressed in units
And also 4 variables, which are coefficients :
W1 : percentage of Demand of the month done during the first week
W2 : percentage of Demand of the month done during the second week
W3 : percentage of Demand of the month done during the third week
W4 : percentage of Demand of the month done during the fourth week
#————————————————————————–
Part 1 : Demo dataset
Let’s create a dataset with 4 products (A, B, C , D) with an identical Demand expressed in monthly bucket.
We’re going to transform the Monthly Demand into Weekly Bucket, using as examples 4 types of distributions :
demand evenly distributed among each week of the month
demand following a “L pattern” (occurring mainly during the beginning of the month)
demand following a “J pattern” (occurring mainly during the end of the month)
demand following a random pattern (with some peaks during some weeks)
a) Product A
#--------------------------------# Input values for the test#--------------------------------# Create a vector of Monthly PeriodPeriod <-c("2023-06-01", "2023-07-01", "2023-08-01")# Create a vector of DemandDemand <-c(1000, 2000, 1000)# assembleinput <-data.frame(Period, Demand)# let's add a Productinput$DFU <-"Product A"# format the Period as a dateinput$Period <-as.Date(as.character(input$Period), format ='%Y-%m-%d')# define weekly distribution valuesinput$W1 <-0.25input$W2 <-0.25input$W3 <-0.25input$W4 <-0.25# keep resultsinput_ProdA <- inputglimpse(input_ProdA)
#--------------------------------# Input values for the test#--------------------------------# Create a vector of Monthly PeriodPeriod <-c("2023-06-01", "2023-07-01", "2023-08-01")# Create a vector of DemandDemand <-c(1000, 2000, 1000)# assembleinput <-data.frame(Period, Demand)# let's add a Productinput$DFU <-"Product B"# format the Period as a dateinput$Period <-as.Date(as.character(input$Period), format ='%Y-%m-%d')# define weekly distribution valuesinput$W1 <-0.75input$W2 <-0.15input$W3 <-0.05input$W4 <-0.05# keep resultsinput_ProdB <- inputglimpse(input_ProdB)
#--------------------------------# Input values for the test#--------------------------------# Create a vector of Monthly PeriodPeriod <-c("2023-06-01", "2023-07-01", "2023-08-01")# Create a vector of DemandDemand <-c(1000, 2000, 1000)# assembleinput <-data.frame(Period, Demand)# let's add a Productinput$DFU <-"Product C"# format the Period as a dateinput$Period <-as.Date(as.character(input$Period), format ='%Y-%m-%d')# define weekly distribution valuesinput$W1 <-0.05input$W2 <-0.05input$W3 <-0.15input$W4 <-0.75# keep resultsinput_ProdC <- inputglimpse(input_ProdC)
#--------------------------------# Input values for the test#--------------------------------# Create a vector of Monthly PeriodPeriod <-c("2023-06-01", "2023-07-01", "2023-08-01")# Create a vector of DemandDemand <-c(1000, 2000, 1000)# assembleinput <-data.frame(Period, Demand)# let's add a Productinput$DFU <-"Product D"# format the Period as a dateinput$Period <-as.Date(as.character(input$Period), format ='%Y-%m-%d')# define weekly distribution valuesinput$W1 <-0.5input$W2 <-0.1input$W3 <-0.3input$W4 <-0.1# keep resultsinput_ProdD <- inputglimpse(input_ProdD)