Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Joining 2 Fact tables on multiple keys based on Condition

Solution: (Conditional Join)

Link Table 1 (Key1) to Table 2 (Key1) if they exist

Else link Table 1 (Key2) to Table 2 (Key2)

Else "NULL".

How do i approach this solution, and build the linking key ?

Any help is appreciated.

Thanks,

3 Replies
ahaahaaha
Partner - Master
Partner - Master

Hi Abhay,

Can still a fragment of the original data and what do you want to get at the output?

Regards,

Andrey

CarlosAMonroy
Creator III
Creator III

Hi Abhay,

Maybe try something like this:

LinkTable:

Load if(len(Key1)>0,Key1,Key2) as Key, Key1 as T1.Key1, Key2 as T1.Key2, Field

From Table1;

join(LinkTable)

Load if(len(Key1)>0,Key1,Key2) as Key, Key1 as T2.Key1, Key2 as T2.Key2, Field

From Table2;

Hope that helps,

Carlos M

aarkay29
Specialist
Specialist

May be something like this :

A:

load * Inline [

A.ID1,A.ID2,Value

1,4,45

2,5,50

3,6,60

];

B:

load * Inline [

B.ID1,B.ID2,Product

1,,A

2,,B

3,5,C

,4,D,

1,4,G

];

Left Join (A)

Load 

  B.ID1 as A.ID1,

  Product

Resident

  B;

Join (A)

Load 

  B.ID2 as A.ID2,

  Product

Resident

  B

Where

  Not exists(A.ID1,B.ID1)

;

Drop Table B;