1 Reply Latest reply on Apr 18, 2016 3:49 PM by diego.medrano

    Showing actuals and forecast as dual axis: Tableau-R Integration

    Sidhu Suresh



      Recently came across a blog by Brad Llewellyn related to Predictive Analysis in Tableau.

      He had done a good job in integrating Tableau to R and have done complex forecasting analysis in Tableau.

      I tried to recreate the same and use the following R Script to get the forecast.



           ## Creating vectors

          hold.orig <- .arg4

          len.orig <- length( hold.orig )

          len.new <- len.orig - hold.orig[1]

          year.orig <- .arg1

          month.orig <- .arg2

          sales.orig <- .arg3

          ## Sorting the Data

          date.orig <- year.orig + month.orig / 12

          dat.orig <- cbind(year.orig, month.orig, sales.orig)[sort(date.orig, index.return = TRUE)$ix,]

          dat.new <- dat.orig[1:len.new,]

          ## Decomposing the Time Series

          timeser <- ts(dat.new[,3], start = c(dat.new[1,1], dat.new[1,2]), end = c(dat.new[len.new,1], dat.new[len.new,2]), frequency = 12)

          seasdec <- stl(timeser, s.window = 'period')

          ## Predicting the new Observations

          for(i in 1:len.new){if(dat.new[i,2] == month.orig[len.new + 1]){start <- i; break;}}

          pred <- seasdec[[1]][start:(start + hold.orig[1] - 1),1] + seasdec[[1]][len.new,2]



      ATTR( YEAR( [Date] ) ), ATTR( MONTH( [Date] ) ), SUM( [Amt] ), [Months to Forecast] )


      I am getting the forecast and used the calculated field DATEADD('month',[Months to Forecast],[Date]) to offset the date to future.


      Currently, my requirement is to show actual and forecast in in the same sheet as a dual axis. Please guide me on how to proceed.