Alteryx Designer Desktop Discussions

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

How to select samples based on category and user input.

WuQi
5 - Atom

Hi all,

 

I want to do a random sampling for multiple categories available in one column. Is there a way to select different number of samples for different category? Please see an example below.

WuQi_0-1660212679831.png

 

The total amount of samples to select is given by the user via Text Box. Here I have three values under the [group] column, I plan to generate samples for those three groups as evenly as possible. If the user wants to select 7 samples in total but 7 is not divisible by 3, then the output will be 2, 2, 3. So can I use a if-else condition here to set the number accordingly? How to achieve in the analytics app? Thanks in advance!

6 REPLIES 6
LouisJ
8 - Asteroid

Hi,

There is a group functionnality in the 'Sample' tool. If you for example select 'First 2 Rows' and then select group by your 'Group' column, it will output the first 2 rows for each unique value in the 'Group' column.

 

In your case, 2 rows * 3 possible groups -> 6 output rows, 2 from each group.

 

In the action tool, you can put a floor function to get an equal division between the records.

LouisJ_0-1660218137768.png

 

I attached my workflow, I hope this helps you out,

Louis

vlad_kutateladze
8 - Asteroid

Hi 

Please check this.

 

vlad_kutateladze_1-1660237852929.png

 

 

 

ChrisTX
15 - Aurora

I used a batch macro, which allows a control parameter to update the number in the Sample tool.

 

 

ChrisTX_0-1660235223255.png

 

 

Chris

WuQi
5 - Atom

Hi Louis,

 

Thanks very much for your reply. The solution is perfect for a user input that is divisible by 3. Since I would like to select the exact same amount of samples as the user input, there may be different number of samples selected from each category. Say, I select 2 samples for category 1 and 2, but 3 samples for category 3. Is that possible? Thanks!

 

Regards, Qi

WuQi
5 - Atom

Hi vlad_kutateladze,

 

Thanks for your solution! I will try out.

WuQi
5 - Atom

Hi Chris,

 

Thanks for your solution! I will try out.

Labels