Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

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

Join 2 Data sources with nearby value

Irfan
6 - Meteoroid

Hi,

 

Currently working on a report where I have to find the cash short/over.

Basically we have sales data (Table 1) and bank deposits data (Table 2) and trying to find the amount variance.

Challenge is Bank deposits data we don't have the sales date. So basically we don't have any fields which we can use to join them.

The logic is we have to find the nearby date and nearby value. 

 

Below is sample data-

 

Table1Table 2 
Sale DateCash CollectedDeposit Date Bank Deposit Variance
2019-06-03199.082019-06-07199.62                  0.54
2019-06-04147.992019-06-07147.97                -0.02
2019-06-051292019-06-07129.8                  0.80
2019-06-06180.832019-06-07180.94                  0.11
2019-06-07177.942019-06-10171.82                -6.12
2019-06-08166.192019-06-10165.71                -0.48
2019-06-09219.752019-06-10219.16                -0.59
 1220.78 1215.02                -5.76
     
Sale DateCash CollectedDeposit Date Bank Deposit Variance
2019-06-10117.62019-06-14114.82                -2.78
2019-06-11125.732019-06-14128.24                  2.51
2019-06-12137.62019-06-14137.61                  0.01
2019-06-13183.182019-06-14183.79                  0.61
2019-06-14161.262019-06-17161.15                -0.11
2019-06-15247.712019-06-17248.92                  1.21
2019-06-16205.442019-06-17199.93                -5.51
 1178.52 1174.46                -4.06

 

Any help would be appreciated.

 

Regards,

Irfan

6 REPLIES 6
danilang
19 - Altair
19 - Altair

Hi @Irfan 

 

Here's a workflow that does what you're looking for

 

Main.png

 

It uses 2 iterative macros.  The first one finds the correct deposit date for each of the sales dates.  The second one compares each sale to all corresponding deposits on correct deposit date and assigns the one where the variance is the smallest

 

Here are the results

 

Results.png

 

Dan

Irfan
6 - Meteoroid

Thank You so much Dan.

 

I appreciate your help.

 

It's working but for couple of date range getting issues, same bank deposits joining twice with sales. See attached screen shot.

 

Result should be like-

Sale DateCash CollectedDeposit Date Bank Deposit Variance
2019-05-20156.762019-05-24156.73             (0.03)
2019-05-21157.22019-05-24158.34               1.14
2019-05-22175.492019-05-24175.45             (0.04)
2019-05-23136.582019-05-24136.55             (0.03)
2019-05-24149.22019-05-28149.63               0.43
2019-05-25191.472019-05-28132.14          (59.33)
2019-05-26118.932019-05-28118.93                      -  
danilang
19 - Altair
19 - Altair

Hi @Irfan 

 

I had to change the way the Closest Amount macro worked to remove a value from the deposit list once it was used. 

 

Dan 

Geoowl
7 - Meteor

Thanks for posting @Irfan - It's an interesting problem.

 

Just adding thoughts to @danilang's solution which looks great:

 - You may want to build in a threshold whereby some records will simply be left unassigned (if the variance is very high and/or days between deposit and sales date is large).

 - Currently solution is based on variance only, whereas a weighting to also use difference between dates might help (i.e. variance of 10 days and $1 in cash is perhaps a worse match than an exact match on date and a variance of $1.5). If you wanted to include, simply calculating datetimediff in days and creating a scored ranking combining this and variance and finally sorting on this gives you a combination of the two. You could also produce a %match column based on this, which would also allow you to filter for matches below a threshold in response to first point. Of course, weighting between these two is more of an art than science.

 

Best of Luck,


Matt

Irfan
6 - Meteoroid

Hi Dan,

 

Awesome!

 

It would be great if you can update the macro. In case exact match don't lookup the nearby value.

 

Please see the attached screen shot.

 

Result should be like below-

Sale DateCash CollectedDeposit Date Bank Deposit Variance
2019-05-13219.252019-05-17219.22             (0.03)
2019-05-14133.862019-05-17133.86                      -  
2019-05-15192.762019-05-17192.76                      -  
2019-05-16137.732019-05-17137.61             (0.12)
2019-05-17204.52019-05-20197.2             (7.30)
2019-05-18153.052019-05-20153.05                      -  
2019-05-19197.812019-05-20197.81                      -  
danilang
19 - Altair
19 - Altair

Hi @Irfan 

 

I'll have to think about this one.  All the exceptions that you're finding are slowly turning this into an optimization problem where you're trying to minimize the total variance in any deposit period.  

 

Dan

Labels