Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

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

Iterative Workflow, Random Sample

calebjones
5 - Atom

Hello! 

 

I have a set of data with a "program" column that could contain multiple (and a variable number) of groups. 

RecordNameProgram
1JohnA
2MaryA
3SueA
4JennyB

5

BobA

6

ClarkC

7

JimmyC

8

PrestonB

9

RaymondB

10

DoeA

11

PeterC

12

CalvinB

13

TommyA

I also have a predetermined, and variable number of records that I need from each group, randomly selected. The quantity to select for each group is stored in an xlsx/csv file. 

ProgramQty of Records to Randomly Select
A1
B3
C1

I need to have a macro that will accept the CSV with the quantities as an input, as well as the actual database records, and then output a set of records randomly selected in the quantities defined. The output should look something like this (sorting is irrelevant so long as its random).

Record IDNameProgram
10DoeA
4JennyB
8PrestonB
9RaymondB
6ClarkC

 

I don't even know where to begin, I think I need an iterative macro, but I don't know how to align the inputs or have two streams going on. Any help would be greatly appreciated! 

2 REPLIES 2
derekbelyea
12 - Quasar

 

 

Here is an ordinary macro that will do what you need.  The macro assigns random numbers to all reords, then sorts the records into groups ordered by random number.  The relevant sample size is then added to each record.  A formula determines if each record is in or out of the sample based on comparing the sequence number of the record to the sample size.  This yields sampling without replacement, which appears to be the requirement.  For the same input the workflow should deliver a different sample on each iteration.

 

 

 2018-02-06_00003.png

 

2018-02-06_00002.png

calebjones
5 - Atom

This is brilliant - thank you!!

Labels