Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

Alteryx Designer Desktop Discussions

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

How to group a file by dates and check if record exists in both groups

mystasz
8 - Asteroid

Hi All!

 

This is my first time in the Alteryx community and I hope to learn a lot from everyone!

 

I have the attached sample data where it includes three columns: Vendor ID, Date and Transaction Amount.

Vendor IDDateTransaction Amt
11/1/2021500
12/2/2021100
23/1/2021200
24/1/2021600
36/1/20211000
36/2/20212000
47/1/20213000
48/1/2021400000
18/5/20215500
18/15/2021500

 

I would like to put Vendor IDs in two groups, based on date and then see if any Vendor ID populates for both Group 1 and Group 2. If it does, I only want to return those records that are in both groups. The output would just display Vendor ID and Sum of transactions between 7/1 - 9/1. 

 

Group 1 = Date between 1/1/2021 - 6/30/2021

Group 2 = Date between 7/1/2021 - 9/1/2021

 

In this case, only Vendor ID 1 populates in both date ranges. Expected output attached. 

Vendor IDSum Transaction Amt
16000

 

What I've done so far is use a formula that would split the Dates into Groups with: 

[Date]>= "2021-01-01" and [Date] <= "2021-06-30" then "Group 1"
else "Group 2"
endif

 

Then I used the Summarize tool to group by Vendor ID and Group. I think created another formula in attempts to find those in both groups but with no luck. 

 

Any help would be appreciated!

6 REPLIES 6
drew9
9 - Comet

Hi @mystasz ,

 

The formula you have is a great start. From there, we can group by Vendor ID and do a distinct count of the Group field we created. If a vendor appears in multiple groups, it will be greater than one. Filter for CountDistinct_group is greater than one, and then join that result back to our original dataset. from there, we simply filter for the date range of 7/1-9/1 and do a sum of Transaction amount by vendor ID. Hope this helps!

drew9_0-1634311390307.png

drew9_1-1634311485901.png

 

mystasz
8 - Asteroid

Hello and thank you! Can you upload the workflow so I can follow better?

drew9
9 - Comet

Sure!

mystasz
8 - Asteroid

Thank you! 

 

Also, I'm sorry I messed up on the description I needed. If I wanted to  populate only those vendors that are in Group 2 but not in Group 1, would Count > 1 still be relevant?

 

For example:

Vendor IDDateTransaction AmtGroup
11/1/2021500Group 1
12/2/2021100Group 1
23/1/2021200Group 1
24/1/2021600Group 1
36/1/20211000Group 1
36/2/20212000Group 1
77/1/20213000Group 2
78/5/2021400000Group 2

 

Vendor ID 7 was in Group 2 but not in Group 1. 

Vendor IDTransaction Amt
7403000
drew9
9 - Comet

Similar process as last time, this time we are looking for where distinct count of group equals 1, and where the concatenation of group contains group 2. Attached an example below 🙂 

mystasz
8 - Asteroid

You have been super helpful!! Thank you very much for your prompt response. 

Labels
Top Solution Authors