Important Community update: The process for changing your account details was updated on June 25th. Learn how this impacts your Community experience and the actions we suggest you take to secure your account here.

Alteryx Designer Desktop Discussions

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

How to join tables with conditions on dates

RBF
7 - Meteor

Hello

 

I have a challenge.  I'm trying to join two tables.  Mock data below:

 

Price data:

ProductPriceCurrencyChanged onTime
115GBP20221106062930
113GBP20221106064310
114GBP20230409103347
212EUR20221231134232
211EUR20230301140736
39GBP20220912090806
38GBP20220912134702
37GBP20230518133417
310GBP20230701141424
46EUR20230501

130800

 

Order Data:

OrderProductSale DateSale Time
112022-11-0710:33:45:0000000
212022-11-0606:29:50:0000000
322023-01-0712:55:25:0000000
432022-12-3123:10:27:0000000
532023-06-1207:05:15:0000000
642023-05-0104:16:04:0000000
732023-08-0113:28:58:0000000
822023-05-0511:05:14:0000000
942023-06-0111:58:25:0000000
1022023-04-0104:40:25:0000000
1122021-01-0111:07:14:0000000

 

For each record, I want to pull in the price that was valid at the date/time of the order.  
1. if no Price exists that is older than the order date, then take the oldest Price available
2. Otherwise, take the Price that was the MAX date before the order date

Here would be the output:

OrderProductSale DateSale TimePriceCurrency
112022-11-0710:33:45:000000015GBP
212022-11-0606:29:50:000000015GBP
322023-01-0712:55:25:000000012EUR
432022-12-3123:10:27:00000008GBP
532023-06-1207:05:15:00000007GBP
642023-05-0104:16:04:00000006EUR
732023-08-0113:28:58:00000007GBP
822023-05-0511:05:14:000000011EUR
942023-06-0111:58:25:00000006EUR
1022023-04-0104:40:25:000000011EUR
1122021-01-0111:07:14:000000012EUR

 

what would be the approach in alteryx?

4 REPLIES 4
ShankerV
17 - Castor

Hi @RBF 

 

Please use the below steps to reach the expected output.

 

Step 1: Input both the data's.

I consider Product as Dataset 1

and Sale as Dataset 2

 

Step 2: Use Formula tool for both Dataset 1 and Dataset 2 to convert the date into ISO format YYYY-MM-DD HH:MM:SS

 

Step 3: Join both the datasets using Join tool [Join by specific records, Product]

 

Step 4: Then use the Filter tool with condition where the Converted date of Sale > Converted date of Product

[DateOrder] > [DatePrice]

 

Step 5: Sort tool, DatePrice -> Descending 

 

Step 6: The use the sample tool to select only 1st record based on Order.

First N Rows

N = 1

Order [check box should be ticked]

 

Many thanks

Shanker V

ShankerV
17 - Castor

Hi @RBF 

 

Step 2: Formula tool formula which I incorporated is 

 

For dataset 1:

Heading of new column: DatePrice

Left(tostring([Changed on]),4) +"-" + Right(Left(tostring([Changed on]),6),2) + "-" + Right(tostring([Changed on]),2) + " " + Left(tostring([Time]),2) + ":" + Right(Left(tostring([Time]),4),2) + ":" + Right(tostring([Time]),2)

 

For dataset 2:

Heading of new column: DateOrder

[Sale Date] + " " + Left([Sale Time], 8)

Felipe_Ribeir0
16 - Nebula

Hi @RBF 

 

Here is a way to go:

 

Workflow.png

RBF
7 - Meteor

Gosh, so many replies already!  Thank you everyone.  Give me some time to work through your suggestion and then I'll see which one works best :)

 

Labels