2 Replies Latest reply on Jun 15, 2017 2:00 PM by Bora Beran

    calling SCRIPT_REAL from a CASE is executing every WHEN clause

    Christoph Henle

      Hi,

       

      I am using a parameter to set which type of regression model should be calculated with an R-Script. When checking the Parameter with a CASE WHEN staement Tableau executes not only the script in the matching WHEN clause but executes all script calls. It returns only the results of the correct one but I would like to prevent the other calls. Any ideas? Thanks!

       

      CASE ([Regression_Type])

      WHEN 1 THEN

          SCRIPT_REAL("

          ar1<-.arg1;

          ar2<-.arg2;  

          model <- lm(ar1 ~ ar2 + I(ar2^2), na.action=na.exclude);  

          predicted.intervals <- predict(model,data.frame(x=ar1),interval='predict',level=0.95);

          predicted.intervals[,1]; 

          ",AVG([Baseline_Y]),AVG([Baseline_X]))

      WHEN 2 THEN

          SCRIPT_REAL("

          ar1<-.arg1;

          ar2<-.arg2;

          model <- lm(ar1 ~ ar2 + I(ar2^2), na.action=na.exclude);  

          predicted.intervals <- predict(model,data.frame(x=ar1),interval='predict',level=0.99);

          predicted.intervals[,1]; 

          ",AVG([Baseline_Y]),AVG([Baseline_X]))

      WHEN 3 THEN

          SCRIPT_REAL("

          ar1<-.arg1;

          ar2<-.arg2;

          model <- lm(ar1 ~ ar2, na.action=na.exclude);  

          predicted.intervals <- predict(model,data.frame(x=ar1),interval='predict',level=0.95);

          predicted.intervals[,1]; 

          ",AVG([Baseline_Y]),AVG([Baseline_X]))

      WHEN 4 THEN

          SCRIPT_REAL("

          ar1<-.arg1;

          ar2<-.arg2;

          model <- lm(ar1 ~ ar2, na.action=na.exclude);  

          predicted.intervals <- predict(model,data.frame(x=ar1),interval='predict',level=0.99);

          predicted.intervals[,1]; 

          ",AVG([Baseline_Y]),AVG([Baseline_X]))

      END