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: 
Not applicable

Join a table with another table using subset of first table's key

Hi,

the title might be confusing but here is the idea:

I have 2 tables and I want to join both tables, but....

here is the case:

table1:

CodeDescription
101.110.255Desc1
101.100.202Desc2
101.200.301Desc3
202.110.111Desc4
202.100.200Desc5
302.300.100Desc6

table2:

CodeGroupGroupName
101.1Current Asset
101.200Fixed Asset
202.11Income
202.10Other Income
302.3

Other Income

The expected result is:

CodeDescriptionCodeGroupGroupName
101.110.255Desc1101.1Current Asset
101.100.202Desc2101.1Current Asset
101.200.301Desc3101.200Fixed Asset
202.110.111Desc4202.11Income
202.100.200Desc5202.10Other Income
302.300.100Desc6302.3Other Income

I want to show which code belong to which CodeGroup and GroupName.

Thanks for your help

1 Solution

Accepted Solutions
flipside
Partner - Specialist II
Partner - Specialist II

Hi Reynald,

You can build an intermediate lookup table to join the two tables as this ...

Lkp:

LOAD Code, text(left(Code,5)) as Key resident Table1;

LOAD Code, text(left(Code,6)) as Key resident Table1;

LOAD Code, text(left(Code,7)) as Key resident Table1;

inner join (Lkp)

LOAD text(CodeGroup) as Key, GroupName resident Table2;

Note the text statement around the Code field as the CodeGroup values are numeric whereas the Codes are not.

flipside

View solution in original post

4 Replies
chematos
Specialist II
Specialist II

Hi,

If that are the only data you have to join, you could create two fields in both tables with the first 5,6 characters so you will have the Keys to join the tables.

Table1:

Load *,

Left(Code,5) as %Key,

Left(Code,6) as %Key2

From TABLE1;

Left join(Table1)

Load *,

if(len(CodeGroup)=5,Left(CodeGroup,5)) as %Key

From TABLE2;

Left join(Table1)

Load *,

if(len(CodeGroup)>5,Left(CodeGroup,6)) as %Key2

From TABLE2;


I ' ve don't try this, hope this helps

flipside
Partner - Specialist II
Partner - Specialist II

Hi Reynald,

You can build an intermediate lookup table to join the two tables as this ...

Lkp:

LOAD Code, text(left(Code,5)) as Key resident Table1;

LOAD Code, text(left(Code,6)) as Key resident Table1;

LOAD Code, text(left(Code,7)) as Key resident Table1;

inner join (Lkp)

LOAD text(CodeGroup) as Key, GroupName resident Table2;

Note the text statement around the Code field as the CodeGroup values are numeric whereas the Codes are not.

flipside

Not applicable
Author

Hi, thanks for ur help btw.

I havent tried any of the solution

but once Ive tried, i will inform my progress.

Thanks anyway

Not applicable
Author

Thanks flipside,

Your solution worked like charm.

Thank you so much.