Alteryx Designer Desktop Discussions

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

Left join: Getting columns of left table only if key not present in the right table

sagarghimire
6 - Meteoroid

Trying to dynamically get just the columns from the left table when doing left join if there is no 'key' columns match to the right column. i.e. do not append right table columns which would all show null except the key (assuming it is not null)

 

TIA

5 REPLIES 5
FrederikE
13 - Pulsar

Hey @sagarghimire,

 

Can you describe in more detail what your problem is?

Because from what I understand, you just want to have the left columns when doing an unmatched Join (Left Join). But this is already the way Alteryx does it by default.

sagarghimire
6 - Meteoroid

Logic I am trying to implement:

If there is a match between Key1 and Key2 and date is between start and end date on lookup table return any one row ( there can be multiple records that may match) that matched.
Only if there is no match on Key 1 and Key 2 combo, join on key 3 (it is just one same value in main table for all records), if there is a match return any one row that matched.

 

Result desired:

Key1Key2datekey3IDstart dtend dtkey3numbernumber id
1a1/1/2021ea112/12/20201/5/2022a123410
2b1/2/2021ea2nullnullnullnullnull
2c1/3/2021ea31/1/20211/5/2022c345630
4d1/4/2021ea41/1/20211/2/2021e89750

Main

Key1Key2datekey3ID
1a1/1/2021ea1
2b1/2/2021ea2
2c1/3/2021ea3
4d1/4/2021ea4

Look up

Key1Key2start dtend dtkey3numbernumber id
1a12/12/20201/5/2022a123410
1a12/15/20211/1/2021b123420
2c1/1/20211/5/2022c345630
4d12/20/202012/20/2023d56740
4d1/1/20211/2/2021e89750

 

Prometheus
12 - Quasar

@sagarghimire The first thing I did was turn the dates into actual dates using DateTimeParse and changing the data type in the following Join tools. I joined the tables on key 1 and key 2 in the first Join tool. Anything that wasn't joined was joined again with the lookup table on key 3. I filtered the records that were joined at the first Join tool to only allow records where date was between start dt and end dt. Then I unioned them the outputs of the Filter tool and the second Join tool and sorted on key 1 to match your expected results.

Parse to Date.PNG

Join on key 1 and 2.PNG

Filter for date.PNG

Join on key 3.PNG

Look up.PNG

sagarghimire
6 - Meteoroid

This is great. Apologies, I missed one important scenario in my original example. If I were to update the second record of look up table start date as follows for example, I would get 5 records in my final output versus just four. Need to just keep one row that fulfils the in between condition out of the two records(could be multiple in real case) that matched. 

 

1a1/1/20211/1/2021b123420
Prometheus
12 - Quasar

@sagarghimire I added a Unique tool between the first Join (J anchor) and the Filter tool and checked the boxes next to key 1 and key 2.

Unique.png

Look up.PNG

Labels