Using R forecast from Tableau


  • RStudio (with forecast package installed)
  • Tableau Desktop (with connectivity established to RServe service.¬†For details of R integration with Tableau, please refer my previous post here)
  • R Programming knowledge
Download source files used for this article

Forecasting allows business to arrive at more realistic estimates and targets for future. Tableau analytics provide the option of generating forecasts which many of you must be familiar with. In this article, we will look at how to make use of the R forecast package from Tableau. This will be a reference for the capabilities that you can bring in from R.

For a simple demonstration of R forecast, we can use the R air passenger time series data set for 2 year forecasting as below

myts1 <- ets(AirPassengers)
plot(forecast.ets(myts1, h=24))


Tableau’s native forecasting has similar capability – an example shown below using the superstore dataset


For the R integration, start a new sheet connecting to globalstore dataset and generate timeseries graph for sales (orderdate by months and Sum[Sales])


To generate a forecast using R package, create a calculated field with the script as shown below


myts <- ts(.arg1,start=c(2011,1), frequency=12);
myforecast <- forecast(myts, h=.arg2[1]);
append(.arg1[(.arg2[1]+1):monthsts],myforecast$mean,after= monthsts
SUM([Sales]),[Forecast Months])

The scripts creates timeseries for sales starting Jan 2011, generates forecast and appends starting x months (specified by parameter ‘Forecast months’) before the last month in the series.

You can view the forecast series by adding calculated field (SalesForecast) to the row. To make it intuitive, create the formula isForecast as below and drag to color.



Forecast vs Actual

To view forecast vs actual side by side, you can add sales to row


But this does not give you a clear understanding or limits your ability to compare. The solution is to bring them together (dual-axis) and then synchronize both axis. The result is shown below


Download source files used for this article