Alteryx Designer Desktop Discussions

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

Finding combinations of numbers adding to a given sum

MsBindy
8 - Asteroid

Here is my dilemma.  I have a large file of data...maybe a millions rows (I'm sure I can narrow this down).  One of the fields is a value.  I want to find combinations of records where the sum of the value equals a given number.  I don't have an example because I don't even know where to begin.

 

For example,  let's say I'm looking for $1,410.15 within the data set.  That amount could be made up of any number of records that net to $1,410.15.

 

Has anyone built anything for this type of scenario in Alteryx?  I've seen some stuff on the internet but it looks too advanced for me.

11 REPLIES 11
ian_hedrick
5 - Atom

@AmitMiller 

Hi, is there a way to modify this so that you are only given one combination and not every possible combination? Trying to help cut down on the time it takes for the workflow to run with 200+ records. Thanks in advance!

dsandmann
8 - Asteroid

@ian_hedrick 

You just need to make some minor changes to the code that generates combos of different lengths:

 

# Generate combinations of different lengths
for r in range(1, len(values) + 1):
    for combination in itertools.combinations(values, r):
        if sum(combination) == target_amount:
            valid_combinations.append(combination)
            break
    if valid_combinations:
        break

 

 

Labels