community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.

Random Sample Based on Population Range

Highlighted


I am looking to see if there is a way to get sample size by Population Range, not % of the population.

This is the ask I have based on the chart:

 

Population Size RangeSample Size
366+25
53-36515
13-525
5-122
2-42
11

 

Thank you,

 

Anna

Alteryx Partner

My understanding is that you have some data, each record having a population size, and you want to group these into ranges and count how many records fall into each range. If this is correct, you could add a Formula tool with a Switch statement to create a new field, then group based on that and perform a count. The switch would look something like:

 

SWITCH([pop], "366+", [pop] >=53 AND [pop] <=365, '53-365',
[pop] >=13 AND [pop] <=52, '13-52', [pop] >=5 AND [pop] <=12, '5-12', [pop] >=2 AND [pop] <=4, '2-4', [pop]=1, '1')

 

Essentially, the syntax is:

 

Switch([FieldToLookAt], "Default Value", Case1, Value1,...,CaseN, ValueN)

 

Let me know if this helps or you need some clarification.

 

Cheers!

I might have not been clear, but it is not that each record has population size, but my entire dataset is the size of that many records. My final output is the random sample of records, but how many records I get would vary. So if I count all my rows and have only 4 records - I want only 2 random records to show up as my final output. If I end up with 300 records, then I want a sample of 13 records, etc. Hope that makes sense now because I am not trying to create a new field that is calculated based on another field.

 

Thank you,

 

Anna

Alteryx Partner

Ah I see,

 

In that case, I think you could create a batch macro that would do what you need. I've attached a workflow below:

 

Spoiler
dynamicrandomsample.PNGdynamicrandomsamplemacro.PNG

This counts your records, and then determines the desired number of samples using your table. Passing it to the Batch Macro, with Samples as the control parameter allows you to update the Random Sample Tool

 

Let me know if this helped,

 

Cheers!

Labels