Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Sampling - Applying logic from "first N rows" but in a random way

srea541
8 - Asteroid

Hi,

I currently have a sampling tool which is set up as follows:

srea541_1-1669050768798.png

I'm trying to get two of each name appear, with random Record IDs being selected rather than the first two rows how would I do this?

 

The output I currently get is correct in terms of structure but some record IDs appear 80-something times (due to picking the first two rows):

 

The distribution of the questions should look like this (every question should be counted twice - unless there are less than 2 instances of it being answered):

srea541_3-1669050825681.png

 

Is there a better way to do this?

 

 

7 REPLIES 7
DataNath
17 - Castor
17 - Castor

Hey @srea541 if you want to pull out a random 2 records for each Name then you could do something like this, whereby the batch macro pulls in one block of Names at a time, extracts a random 2 records from this set and then outputs this back into the main workflow. A quick example...

 

Here I have 1-100 for every letter of the alphabet:

 

DataNath_0-1669053724445.png

 

Inside the macro:

 

DataNath_1-1669053756592.png

 

Output:

 

DataNath_2-1669053772754.png

 

Hope this helps but please let us know if you were looking for something else! :)

ShankerV
17 - Castor

Hi @srea541 

 

It can be achieved in a simple way.

 

Please find the solution below.

 

ShankerV_1-1669106204686.png

 

 

ShankerV_0-1669106176004.png

 

 

Kindly accept this solution if it provided a solution to your question.

 

Many thanks

Shanker V

 

 

 

DataNath
17 - Castor
17 - Castor

@ShankerV as noted in the help documentation, using the 1 in N option won't consistently bring back the same amount (2) of records for each [Name]. See here - providing a 1 in 50 chance brings back 1 of some records, 0 of some and lots of others.

 

DataNath_1-1669108775408.png

ShankerV
17 - Castor

Hi @DataNath 

 

I tried to resolve only part of problem, where 

I'm trying to get two of each name appear, with random Record IDs being selected rather than the first two rows how would I do this?

 

To overcome this problem, we can use the method which I have mentioned where it will fetch random Record IDs as per the requirement.

 

To overcome the other points, I was assuming it can be overcome with Summarize tool and Filter according to the requirement.

The distribution of the questions should look like this (every question should be counted twice - unless there are less than 2 instances of it being answered):

 

Please let me know if otherwise as I might have not understood the second instance incorrecty.

 

Many thanks

Shanker V

srea541
8 - Asteroid

Hey @DataNath Thank you for sharing this! Would you be able to save it in a way that I could open it on Alteryx 2020.4 please? 

 

Many thanks! 

DataNath
17 - Castor
17 - Castor

No problem @srea541, please find them attached.

 

As a note, you can change the version of Alteryx assets by navigating to them and right click > open them within a text editor. You just need to find the version (which is in the top few lines) and change it there:

 

DataNath_1-1669292623395.png

 

Would recommend creating a copy if you do this, as this can corrupt your files if you accidentally delete/add other parts.

srea541
8 - Asteroid

@DataNath Thank you so much for sharing this - works perfectly!! :)

Labels
Top Solution Authors