6

How to generate pseudo random numbers and row-counts in Tableau? I didn't find any built-in functions (like 'RAND', 'RCOUNT').

Alexander
  • 1,889
  • 15
  • 29
Lalitha03
  • 101
  • 1
  • 8
  • 2
    you could use the `sql functions` if your connecting to a _RDBMS_ like this `RAWSQLAGG_REAL("RAND()")` – vhadalgi Nov 23 '15 at 11:27

1 Answers1

5

Edit: Just learned that there is a Random() function in Tableau. It is not in the library but if you use it anyway, it will tell you that the formula is valid and create a value between 0 and 1.

Original and still valid answer in case you want to use officially supported functions:

Since Tableau is used to create graphs based on your data, there is usually little use for random numbers (would you explain what you need them for?)

However you could use an approach like this to work around this limitation: http://community.tableau.com/docs/DOC-1474

Basically getting a semi-random seed out of the time, combine it with other values based on table calculations and multiplying it with other semi-random values

Seed
(DATEPART('second', NOW()) + 1) * (DATEPART('minute', NOW()) + 1) * (DATEPART('hour', NOW()) + 1) * (DATEPART('day', NOW()) + 1)

Random Number
((PREVIOUS_VALUE(MIN([Seed])) * 1140671485 + 12820163) % (2^24))

Random Int
INT([Random Number] / (2^24) * [Random Upper Limit]) + 1

Where [Random Upper Limit] is a user defined value to limit the range of the result.

Alexander
  • 1,889
  • 15
  • 29
  • Awesome! Thank you @Alexander. RANDOM() worked!! Basically, I'm trying to manipulate data by giving a random number to show values like 'quantity'. – Lalitha03 Nov 23 '15 at 11:38
  • 1
    The undocumented random() function is not available in every data source, depends on the driver – Alex Blakemore Jan 16 '17 at 02:48