Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

How to work out all permutations within groups

jt_edin
8 - Asteroid

I'm not entirely sure if this is a combination or permutation problem, or something in between. I'm trying to figure out how to use Alteryx to enumerate all possible combinations of individuals to groups.

 

Let's say I have four people (A, B, C, D) to split into two equal groups. The group order or name doesn't matter, they just have to be separate groups. I think we could split them into three different combinations of two:

 

AB|CD ; AC|BD ; AD|BC

 

Obviously we can only use each person once. And because the group order doesn't matter, something like CD|AB doesn't count as a new combination because it's just the same as AB|CD. Hence the group order not being important.

 

If we had six people we could split them into three groups of two. I guess like this:

 

AB|CD|EF ; AC|BD|EF .... etc etc

 

How do I work out all the possibilities? And what if I had 12 people and wanted to split them into 3 groups of 4 people? Or 4 groups of 3 people? How would I go about enumerating all those possibilities? I can't quite get my head around it. Help required! There's probably a nifty little R function that can do this with one line of code, but help is required! Thanks

7 REPLIES 7
Dynamomo
11 - Bolide

@jt_edin 

That was fun but a bit tougher than I originally thought 😉

I created an iterative macro to create the unique pairs, then used a bunch of other tools including Make Group to identify the unique combos.  I think it works.  Lemme know what you think.

jt_edin
8 - Asteroid

Thank you very much, how helpful. Please would you be able to share the macro too, or perhaps package up both as a zip file or something? Thanks!

Martyn
9 - Comet

This is a tricky one.

 

I did the following to get 12 people split into 3 groups of 4 people -

Martyn_0-1572000745628.png

 

The first part (up to the summary) generates all possibilities of the group. 12! / (8! * 4!) = 495 different combinations.

 

The second part appends and filters (check that a person in group 2 is not in group 1) to get all possible combinations for 2 groups and then appends again and filters (check that a person in group 3 is not in group 2 or group 1).

 

This yields 12! / (4! * 4! * 4!) = 34,650 different combinations (you will need to take off the limit of 16 from the Append tools).

 

It should be possible to create a macro to do the first part (setting up the groups) - allowing you to control the group size. And it should be possible to do the second part in a macro as well - allowing control on how many groups (which would be derived from the first part anyway).

 

Be careful of the numbers you are working with though. It may be best to look into an R function for this if the numbers are going any higher.

danilang
19 - Altair
19 - Altair

Hi @Dynamomo 

 

I think you forgot to attach the macro to your post.

 

Dan

Dynamomo
11 - Bolide

Shoot!  So sorry about that.

here is the Alteryx export package containing all of it!  Let me know if you have any questions about it.

jt_edin
8 - Asteroid

Thank you @Dynamomo and apologies for the delay. How difficult would it be to adapt the group size? Say we wanted to specify an integer for the group size, could be 3, 4, 5 etc? Thanks

Dynamomo
11 - Bolide

Hi @jt_edin ,

I'm not sure that i follow what you mean by specify an integer.

If you mean enter a value like 4 and then have it create groups for values 1,2,3 and 4, I would not change the macro but simply add a generate rows tool to create unique a unique id starting at 1 and ending at the integer that you enter (in this case 4).  

if you want this to be in the macro, it wouldn't be hard...you could have two radio buttons where the user chooses between entering an integer or reading in the values from a field...

Let me know if that makes sense or if I have misunderstood.

Maureen

Labels