7 Replies Latest reply on Jan 16, 2019 4:19 PM by Jacob Decker

    How to get static random number?

    Julia Tran

      Hello, I am hoping someone could let me know how I can assign a random number between 0 and 1 to each of my raw data rows, and have the random number remain static.  Is this possible in Tableau?  In Excel, I would use the random function, then copy and paste as value to keep the numbers static.  Right now, in Tableau, the random values are recalculating every time I change calculations in the sheet.

       

      I am using Tableau 10.5.2, but I do have Tableau 2018 as well.  Just haven't installed it yet.

       

      Thanks for any pointers,

      Julia

        • 1. Re: How to get static random number?
          patrick.byrne.0

          Hello Julia,

           

          This is a very interesting scenario and use case for Tableau. In the given scenario the numbers are going to recalculate every time the viz is updated as you have seen. Because every time that column is used the RAND() will be enacted. There is not a currently a way to prevent this from updating without simply preventing the whole workbook from updating. Which if there are changes being made to the Viz it will need to update to render properly.

           

          One workaround would be to create the randomized number column in the data source itself. That way it would be static and reusable.

           

          Cheers,

          Byrne, Patrick

          • 2. Re: How to get static random number?
            Jim Dehner

            Hi Patrick    

            Interesting thought - how would that work to fix a random value for use in other calculations

             

            I think it is important to note here that excel recalculates the random number every time it does a refresh also and the process of copying and pasting a value is like an electronic scratch pad -

             

            Jim

            • 3. Re: How to get static random number?
              patrick.byrne.0

              Sorry if I was unclear. I mean, by generating the randomized column, then inserting just the values as a column into the data source as just values. So not really random I guess. But as you mentioned I believe using any sort of random function will cause the values to change anytime the data is modified.

               

              Cheers,

              Byrne, Patrick

              • 4. Re: How to get static random number?
                Jim Dehner

                OK I get it - I guess if you did that you could also have a parameter (sequential) and use it as a pointer to a random number from the list - the user could then increment the "pointer" or hold it "Fixed" or to recall history?  as long as the column of numbers is random I think the effect is still random

                 

                JIm

                • 5. Re: How to get static random number?
                  Gerardo Varela

                  Hi All,

                    I'm not sure i'm following the full use case but I'm hoping this at least sparks some ideas:

                   

                  Random Numbers (Even with Extracts) | VizPainter

                   

                  So from the example above something to the sort of:

                   

                  (((PREVIOUS_VALUE(MIN(327680)) * 1140671485 + 12820163) % (2^24)))

                  *.00000001

                   

                  That should provide sudo random values from 0 to 1. 

                   

                  Regards,

                  Gerardo

                  • 6. Re: How to get static random number?
                    Peter Fakan

                    Once you calculate your random numbers, extract the data and re-ingest it into Tableau - viola your random numbers are now static.

                     

                    HTH

                     

                    Peter

                    1 of 1 people found this helpful
                    • 7. Re: How to get static random number?
                      Jacob Decker

                      I have figured out a bit of a trick that might work for you (or some future reader).

                       

                      1. create Calculated Field: [Random]

                      random()

                       

                      2. create Calculated Field: [Random Rank]

                      Rank([Random])

                       

                      Put the [Random Rank] as the text data in marks:

                       

                      So now instead of ranking 1234 along a SUM of something etc, it will rank() across whatever that first seed is for the initial random(). The seed never changes. You can change the view filter a bunch of different ways, but when you go back to any view filter it will return the same rows with the same random rank.

                       

                      3. I combined this with a Parameter: "Select How Many" , Integer, 10, automatic, all

                       

                      4.Create top/bottom # filter: [Selection Filter]

                      if [Random Rank]<= [Select How Many] then "Top N" elseif [Random Rank]>size()-[Select How Many] then "Bottom N" else "Others" END

                       

                      Then you can show the [Selection Filter] and "Select How Many" parameter and users can pick how many random records they want and if they somehow don't like that mix of random, then they can just look at the "Bottom N" random ranked outputs.

                       

                      Note: My original user request was "Please give us a random of X dimension, and random Y dimension, and random Z dimension" if you get this ask, note that any multiples of a normally distributed random variable is still a normally distributed random variable. It's not more or less random along any factor, and especially as you start to approach the Central Limit Theorem (>500 best, >350 decent) then you can basically consider those as normally distributed. So having one rank([Random]) set up should give you basically the same outcome probability results.

                      probability - Multiplication of a random variable with constant - Mathematics Stack Exchange

                      Sums of Independent Normal Random Variables | STAT 414 / 415

                      The importance of the normality assumption in large public health data sets. - PubMed - NCBI