Alteryx Designer Desktop Discussions

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

group by unique pairs

kris-2
6 - Meteoroid

Hello!

 

I'm trying to group unique pairs from col A and col B.

For example, I have this dataset:

Col ACol B
AppleRed
RedApple
BananaYellow
GreenBanana
GreenYellow
LemonPink
PinkLemon

What I want to do is to group the unique pairs (in the sample table above, Red Apple = Apple Red. The order does not matter.) My desired output is like this:

Col ACol BGroup
AppleRed1
RedApple1
BananaYellow2
GreenBanana2
GreenYellow2
LemonPink3
PinkLemon3

 

I've tried concatenating Cols A and B to form pairs, but I feel a bit lost and can't seem to find a way to group them. 

6 REPLIES 6
atcodedog05
22 - Nova
22 - Nova

Hi @kris-2 

 

Here is how you can do it.

Workflow:

atcodedog05_0-1648195090730.png

 

1. Using formula tool to calculate pair key by using formula Max([Col A],[Col B])+"-"+Min([Col A],[Col B]). This way it doesn't matter whether the value is in Col A or Col B I will always come in the same order.

2. Using multi-row formula tool to create a new group when pair changes.

 

It's not the same as your expected output and I am not sure about the logic behind your expected output.

 

Hope this helps : )

 

atcodedog05
22 - Nova
22 - Nova

Hi @kris-2 

 

Here is another method that will give you the expected output. But the expectation is that pairs are occurring consecutively.

 

Workflow:

atcodedog05_0-1648196837945.png

 

I am using multi-row formula to check whether [col a] is same as previous row [col a] or [col b] and similarly with [col b] if there are same then add it in the same group or else create a new group.

 

Hope this helps : )

kris-2
6 - Meteoroid

Thanks for sharing your workflow! :) I was hoping rows 3-5 would be in one group as if the pairs are transitive, if that makes more sense...

atcodedog05
22 - Nova
22 - Nova

Hi @kris-2 

 

Check my second response. Hope that helps.

kris-2
6 - Meteoroid

Hi @atcodedog05! Your workflow was very useful, thank you!

atcodedog05
22 - Nova
22 - Nova

Happy to help : ) @kris-2 

Cheers and have a nice day!

Polls
We’re dying to get your help in determining what the new profile picture frame should be this Halloween. Cast your vote and help us haunt the Community with the best spooky character.
Don’t ghost us—pick your favorite now!
Labels