
1. Re: 'What If?' analysis using Monte Carlo method
Jim Wahl Feb 28, 2013 6:06 AM (in response to Mårten Lindblad)I'd love to see it. There is a lot of interest in adding R support to Tableau. You might vote on the feature and add your use case example here: Integrate with R Statistics  Tableau Support Community.
Tableau 8 also allows you to create / edit Tableau extracts with Python (or C or Java), which might be another workaround to get advanced stats in Tableau. Maybe someone could write an R library in C for R to read, write extracts.

2. Re: 'What If?' analysis using Monte Carlo method
Mårten Lindblad Feb 28, 2013 6:28 AM (in response to Jim Wahl)Alright, I'll just generalize the code and I'll upload it in the next few days.

3. Re: 'What If?' analysis using Monte Carlo method
Gerardo Varela Feb 28, 2013 12:13 PM (in response to Mårten Lindblad)Marten,
Please do! I'm sure allot of us will find this useful. If the community adapts it, Tableau will follow.
Gerardo

4. Re: 'What If?' analysis using Monte Carlo method
Saken Kulkarni Jan 3, 2014 11:12 AM (in response to Mårten Lindblad)Hi Marten!
I am trying to create a Monte Carlo simulation in Tableau as well. Would you be able to share your template with me?
Thanks!
Saken

5. Re: 'What If?' analysis using Monte Carlo method
Olga Shafir Jan 21, 2015 2:57 PM (in response to Mårten Lindblad)Marten, do you still have the workbook you could share? Would highly appreciate it!

6. Re: 'What If?' analysis using Monte Carlo method
Joshua Gibbs Jul 1, 2015 11:48 AM (in response to Mårten Lindblad)Hello Marten:
Any chance you still have the workbook available to share? It would be greatly appreciated, as I'm trying to get a monte carlo simulation running in Tableau currently.

7. Re: 'What If?' analysis using Monte Carlo method
Joan Marius Dec 7, 2015 9:58 AM (in response to Mårten Lindblad)Hi Marten,
It would great if you post your Tableau template, because I am trying to create a Monte Carlo Simulation within Tableau.

8. Re: 'What If?' analysis using Monte Carlo method
Sumeet Bedekar Dec 2, 2016 3:51 AM (in response to Mårten Lindblad)Hi All
I am trying to create a Monte Carlo simulation in Tableau as well.
Would you be able to share your template with me?
In my case I have output as  "Market Size in Million" and inputs are  "Avg Price , Penetration , Reuse , Units "
and relation is  Market Size in Million = Avg Price * Penetration * Reuse * Units
What i tried as of now is I have created "What if analysis" . In which I have used parameter in which use can set value say  What will be Market in size for 5% increase in Avg Price. eg Avg Price = 100 after 5% increment it will be 105.
But I want use correct approach to apply simulations on this.
Kindly help and let me know your thoughts.
Sumeet

9. Re: 'What If?' analysis using Monte Carlo method
Drake Morse Jan 12, 2017 7:52 AM (in response to Mårten Lindblad)Hi Marten,
Are you able to share you workbook that you developed? Would love to see it in practice.
Cheers
Drake

10. Re: 'What If?' analysis using Monte Carlo method
Jonathan Basirico Aug 31, 2018 10:17 AM (in response to Mårten Lindblad)I have come up with a way to do a Monte Carlo simulation in R using Tableau. There are really only two main issues:
1.) The script call to R from Tableau only returns a single value so any Monte Carlo outcomes are reduced to a single value (e.g., mean of the outcomes).
2.) The random Monte Carlo variables will be regenerated each time the call to R is made. For example, if I wanted to compare the mean of the Monte Carlo outcomes to the max of the Monte Carlo outcomes using two different calculated fields in Tableau, then I would actually be comparing two different simulations rather than the mean and max of the same simulation. This is because two separate calls to R are being made, and each script has a separate simulation.
The way to address those issues is to:
Step 1: Use the Tableau calculation to check if Monte Carlo random variables have been created. (Use the "exists()" R code).
Step 2: If the random variables are not yet created, then create/store them in an R variable.
Step 3: If the random variables are already created, perform the calculation on those variables.
Step 4: Include this check in every Tableau calculation that refers to the Monte Carlo random variables.
Example Tableau calculation (.arg1, .arg2, and .arg3 are parameters for n, mean, and sd):
script_real(
'if (exists("tab_sim")==FALSE) {
tab_sim = rnorm(.arg1,mean = .arg2,sd=.arg3)
mean(tab_sim)
} else {
mean(tab_sim)
}'
, attr([n]),attr([mean]), attr([sd])
)
Jonathan