Alteryx Designer Discussions

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

Join us on Dec 2 for a half-day virtual analytics + data science event!
US & CA customers only

It's the most wonderful time of the year - Santalytics 2020 is here! This year, Santa's workshop needs the help of the Alteryx Community to help get back on track, so head over to the Group Hub for all the info to get started!

Random Sample Based on Population Range

5 - Atom

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


Thank you,



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.



5 - Atom

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,



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:



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,