Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Pulling two recent payments and difference

Leti
5 - Atom

Hi,
I have a dataset that contains payment information per ID. The frequency of payments for each ID differs, some are paid once a year, others are paid up to 4 times a year. I want Alteryx to pull the two recent payments no matter the date difference, it can be a year apart, and find the difference between them. 

I transformed the data into having a payment date column and payment amount in another column. In attempt of trying to pull the 2 most recent payments per ID, I added a Current Date column to use formulas as a "Max date", but no luck. Then I tried to use Payment ID with Multi-Row Formula, Cross Tab, and Formula tools to find the difference, but not every ID has just 2 payments sitting in the dataset it can contain multiple payments and the formula for each ID would be different.

 

If someone has an idea of how I can approach this, I would appreciate the feedback!

 

Thank You!

 

3 REPLIES 3
Qiu
21 - Polaris
21 - Polaris

@Leti 
If My understanding is correct, we can use the Sample tool to do this.

We sort the data by payment ID accending, and Payment Date in Decending order, then  pick the first 2 records?

1121-Leti.PNG

Leti
5 - Atom

Thank You so much, this works!!

Qiu
21 - Polaris
21 - Polaris

Glad to be any help.

Labels
Top Solution Authors