Alteryx Designer Desktop Discussions

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

Loop a list to extract three of the numbers to make a unique combination

JokeFun
8 - Asteroid

Hi,

Let me just show an example. I need to exaust all the possible combinations of three records from the list. I think iterative macro might help, by extracting 3 each time. But I am not sure how to code in this case. Any good idea?

 

And how about making all combinations of 2, 4, or 5 and so on?

 

Name1Value1RecordIDTotalRecords012345678910111213141516171819202122232425262728293031323334
A10017100100100100100100100100100100100100100100100                    
B15027150150150150150          150150150150150150150150150150          
C15037150    150150150150      150150150150      150150150150150150    
D20147 201   201   201201201   201   201201201   201201201   201201201 
E5157  51   51  51  5151  51  51  5151 51  5151 5151 51
F3067   30   30  30 30 30  30  30 30 30 30 30 3030 3030
G10177    101   101  101 101101   101  101 101101  101 101101 101101101
    400451301280351451301280351352331402181252231501351330401402381452231302281402381452231302281282353332182
6 REPLIES 6
mbarone
16 - Nebula
16 - Nebula

I don't use it much, but have you tried the Permutation Tool on the Data Investigation palate?

JokeFun
8 - Asteroid

@mbarone Hi, Which version you are using? I am using V2020.3.5 and do not have this Permutation Tool.

Christina_H
14 - Magnetar

You can do this with append tools, although if you have a lot of records the numbers will increase exponentially.

Christina_Hurrell_0-1636106026952.png

 

danilang
19 - Altair
19 - Altair

Hi @JokeFun 

 

Here's a different take on the C(n,r) problem.  The overall strategy expresses the values from 1 to 2^n as integers and then takes all the ones that have r bits set to 1.  These combinations are joined to your original data to give you the groups.  You get a large number of intermediate rows, but since they're generated iteratively as opposed to through a Cross Join the algorithm is very fast.    The output is sorted by group and Input row

 

This is slight modification to my solution to Weekly Challenge 231, that allows you to specify the number of unique items in each group.  Since @Kenda, who submitted the original challenge is a vertical User, my solution is also vertical

 

danilang_0-1636210078307.png

 

 

 

 

Dan

JokeFun
8 - Asteroid

@danilang Hi Dan, This is really a great workflow! Actually I don't have much idea of the bin thing, or the 1/0 thing in the workflow. But I see it's absolutely a nice application of those concepts in Alteryx. Thank you very much!

JokeFun
8 - Asteroid

Hi @Christina_H Thank you very much! This is really a simple but great workflow with clear logic. It really gives me many hints.

Labels