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

Grouping and summing without relation

nivnat
5 - Atom

Hi everyone I have a weird question. I have a dataset that looks like this 

 

idamount
1017
101-3
101-4
1018
101-4
101-4

 

How do I group so that amounts 7, -3, -4 are the same group #? The Logic is that 7 + -3 + -4 = 0 so I want to group them together. Similarly 8 + -4 + -4 = 0.

 

For example I want 

idamountgroup #
10171
101-31
101-41
10182
101-42
101-42

 

I tried using summarize but I cant just sum by ID number because most of them have more than one group per ID. The original data set has Date column which really doesn't follow a pattern, and description which again has just an explanation and is sometimes unique to each transaction. 

4 REPLIES 4
fmvizcaino
17 - Castor
17 - Castor

Hi @nivnat ,

 

In my example, I'm admitting that you will always sum 0 for every group and that they are all sorted somehow.

So, after those assumptions, I'm using a running total to do an accumulate sum and then a multi-row to identify the different groups.

 

Take a look at the example and let me know if that works for you.

Best,

Fernando Vizcaino

nivnat
5 - Atom

Many thanks! That works for most of my data. But I forgot to mention that there are a couple groups where the sum need not be zero, but they have to be classified as a different group. The problem with this is it works until it hits a group where sum never becomes zero so for the rest of the id it categorizes it as the same group when it's actually not.

 

I've tweaked the data to include this condition too. What I get is: 

 

idamountgroup
766.671
76-61
76-0.671
939.332
933.672
93-3.672

 

What I need is:

idamountgroup
766.671
76-61
76-0.671
939.332
933.673
93-3.673

 

Any help is much appreciated.

 

fmvizcaino
17 - Castor
17 - Castor

Hi @nivnat ,

 

Maybe I am oversimplifying your problem, but take a look at the example attached and let me know if that works for you.

 

Best,

Fernando Vizcaino

nivnat
5 - Atom

Yes! That solves the problem. To make it understandable, if we think of positives as credit issued and the negatives as credit used, I only needed the ones where the credit was completely used. To use up your credit, you have to have a sum of zero so the first part solves that, for the remaining, I just grouped by the positives because they have credits that are unused.

 

Thanks!

Labels