We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Remove records based on pairing / count

45179902
8 - Asteroid

I have a table that looks like this:

 

Table 1

NumbersSources
5000File A
2000File A
-200File A
200File B
-5000File B
-2000File B
200

File B

 

What I want is to pair the rows in Files A and B where each pair sums to 0. For example the 5000 from File A on row 1 is paired with -5000 from File B on row 5. And 2000 from File A on row 2 is paired with -2000 from File B on row 6, etc.

 

The rule is that the number of negatives and positives from the two files should match. Therefore, in the above example, either the 200 from File B on row 4 or row 7 should be removed because there's only one -200 from File A. This rule shall apply to all input files like these. There must be the same number of positive and the same number of negative, each from a different file. The only two files possible are Files A and B.

 

I've tried many methods but couldn't find a way to solve this. Please note that only solutions that work for all scenarios would be accepted. Please do not hardcode this input file for the desired outcome. The SAME workflow should be tested with other scenarios as well such as below:

 

Table 2

NumbersSources
5000File A
-2000File A
-200File A
200File B
-5000File B
-2000File B

In this case, the -2000 from File A and -2000 from File B do not sum to 0, hence, both should be removed.

 

Table 3

NumbersSources
5000File A
2000File A
-200File A
200File B
-5000File B
-2000File B

In this case, all records shall be kept.

 

Table 4

NumbersSources
5000File A
-2000File A
-2000File A
2000File B
-5000File B
-2000File B

In this case, one of the two -2000 from File A and the -2000 from File B should be removed.

 

Table 5

NumbersSources
5000File A
5000File A
-2000File A
2000File B
-5000File B
-5000File B

In this case, all records are kept.

 

I would appreciate your solution workflow as an attachment coupled with a little explanation.

 

 

4 REPLIES 4
Qiu
21 - Polaris
21 - Polaris

@45179902 
How about the pair 200 and -200 from your 3rd table?

45179902
8 - Asteroid

@Qiu Those are still paired. -200 and 200 are from two files - Files A and B - and they add up to 0.

Qiu
21 - Polaris
21 - Polaris

@45179902 
I can not get touch with Atleryx now, but maybe you can try with an iterative macro?

45179902
8 - Asteroid

Sounds interesting. I haven't used macros for a while. I will look into that but please share a sample when you get a chance.

Labels
Top Solution Authors