Random sampling implementation

Published: 25 Mar 2021
Last Modified Date: 13 Oct 2022


Random sampling implementation in Tableau. Example: Random sampling top 0-9 random customers from the data set



  • Tableau Desktop


1. Create a calculation for Random number generation

Option 1:
Use RANDOM() function:
RANDOM() Function Produces Inconsistent Results

Option 2 :
Use Tabpy

Random function implementation for 0-9 :
SCRIPT_INT("import random
return random.randint(0,9)",SUM([Sales]))

2. Create another filter calculation  INDEX()<[Random function implementation for 0-9]

3. Put Customer name on Rows and Drag filter calculation above to Filters and select True

Every time the sheet is refreshed or the data source is, it will produce random 0-9 customers.
Did this article resolve the issue?