Data Sampling in Tableau
Jatin Garg Feb 14, 2020 9:26 AMI have two datasets (Data A and Data B) which I am joining in Tableau. After joining the datasets I need to sample the data for each cond (cond1 and cond2 below) based on following rules and tag sample in a calulcated field named as RandomSample.
For Cond1
if Date > Date 1 and cond1 = Y then randomly sample 40% of the population.
For Cond2
if Date > Date 1 and cond2 = Y then randomly sample 10% of the population.
Now, If you will look at the final dataset in the end under expected result. It has Random sample column. For cond1, B,C,G,H all have Y in Cond1 and date > date 1. So we do a 40% sample of 4 which is 1.6. Round it to 2. So we tag b and g as Y in Random sample column.
For cond2, D and E have Y in cond2 and Date > Date 1. Here we do a 10% sample of 2 which is 1. So we tag e as Y in random sample.
My question is how do I create this sampling calulcated field RandomSample in tableau? I have attached a test workbook below. I know how to do this in Oracle but I don't have both datasets in Oracle so sampling has to be done in tableau after data has been joined.
Thank you.
Data A  
Name  Cond1  Cond2  Date 
a  Y  2/13/2020  
b  Y  2/14/2020  
c  Y  2/13/2020  
d  Y  2/16/2020  
e  Y  2/17/2020  
f  2/18/2020  
g  Y  2/19/2020  
h  Y  2/20/2020 
Data B  
Name  Date1 
a  2/12/2020 
b  2/13/2020 
c  2/14/2020 
d  2/15/2020 
e  2/16/2020 
f  2/17/2020 
g  2/18/2020 
h  2/19/2020 
Expected Result
Final Dataset  
Name  Cond1  Cond2  Date  Date1  RandomSample 
a  Y  2/11/2020  2/12/2020  
b  Y  2/14/2020  2/13/2020  
c  Y  2/13/2020  2/14/2020  
d  Y  2/16/2020  2/15/2020  
e  Y  2/17/2020  2/16/2020  Y  
f  2/18/2020  2/17/2020  
g  Y  2/19/2020  2/18/2020  Y  
h  Y  2/20/2020  2/19/2020  

Test.twbx 11.6 KB