7 Replies Latest reply on Mar 1, 2016 9:56 AM by mark schukas

    error in Script_Int

    mark schukas

      I get the following error (R is running):

      Error in base::parse(text =      .cmd) : <text>:1:12: unexpected ')' 1: mean(.arg1)) ^

       

      when I run:

      SCRIPT_INT("mean(.arg1))",SUM([Sales]))

      (i'm using the Super Store data file for testing)

      ?

       

      thank you.

        • 1. Re: error in Script_Int
          Bora Beran

          You have an extra )

           

          mean(.arg1))

           

           

          • 2. Re: error in Script_Int
            mark schukas

            ooops...thank you!

             

            what am I actually calculating with this calc. field:

            SCRIPT_INT("mean(.arg1)",SUM([Sales]))  ?

                       n.b., when I put on Viz, SCRIPT_INT("mean(.arg1)",SUM([Sales])) = Sum of Sales (not the average)?

             

            and next, I would like to calculate the average Day of Week Sales (Monday, Tuesday, etc.)?

             

            thank you.

            • 3. Re: error in Script_Int
              Bora Beran

              This would give you avg of sums. Or if your visualization doesn't have aggregation on or it is aggregated at the level of a unique row level identifier and sum won't have any effect so will just give avg.

               

              A few comments 1) mean will probably return a float. Any reason why you use the int function? Do you want rounding?

              2) Why did you want to use R to compute avg of sums. You can do this in Tableau without R using table calculations, LOD expressions or reference lines

               

              If you want to get compute the average week from day of sales. You need to have a WEEK and DAY pill in your sheet. Then you can use this calculation, and from the context menu select computing using > Day.

              • 4. Re: error in Script_Int
                mark schukas

                thank you...

                 

                "average week from day of sales. You need to have a WEEK and DAY pill in your sheet..."

                -this is the rub (you'll see my other posts) - I was able to make a calculated field for Day of Week average (e..g, Sunday, Monday) over a parameter driven start and stop date, but I wasn't able to calculate without having DayofWeek on the Viz (my user doesn't want to see and they don't want it to effect the roll-ups)...

                 

                would you have further thoughts on this problem/issue?

                 

                thank you.

                • 5. Re: error in Script_Int
                  Bora Beran

                  If you don't want to add days to your view and all you want is to do a two level aggregation, the best way to do this is using an LOD expression.

                   

                  Create a calculated field let's call it Calculation1 with the following formula

                   

                  DATEPART('day', [Your Date Field Here]}

                   

                  Then in your sheet add the following formula

                   

                  AVG({include Calculation1 : SUM([Sales])})

                   

                  Since your view has week in it this will compute sum at week, day level then average it to week without adding days into the view.

                   

                  I wrote extensively about LOD calculations if you want to get a good understanding of how they work.

                   

                  What’s new in Tableau 9.0? Part 2 – Level of Detail Expressions « Bora Beran

                  • 6. Re: error in Script_Int
                    mark schukas

                    bonne journée

                    --i have a few questions/thoughts, but to start, why are the two Measures not the same value?

                     

                    merci.

                    • 7. Re: error in Script_Int
                      mark schukas

                      "Since your view has week in it this will compute sum at week, day level then average it to week without adding days into the view."

                       

                      ?can I do this without having the week on the Viz?

                      (I'm reviewing the LOD functions..)

                       

                      thank you.