Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to identify primary key in a table seperated by comma.

Dear Friends

I have two input table

Table 1:

Here Supplier ID is numeric field where mutiple supplier linked with the same contract are enter using comma.

Contract IDSupplier IDProject Status
1232Green
1451,4,6,7Yellow
1673,8,9Red

Table 2:

Here for every supplier ID the respective article & spend is mentioned.

Supplier IDArticleSpend
11234100
11344100
11454100
21564100
21674100
31784100
31894100
42004100
52114100
62224100
62334100
72444100
72554100
82664100
92774100
92884100

I want to

  • count no of article as per contract id ( so it should count the artcle number for all supplier seperated by comma)
  • Sum Spend as per contract id

I am not able to connect the two table as the data in table 1 is seprated by comma & hence not acting as a primary key.

Please help me in case if there is a way around to deal with such issues.

Many Thanks

Best Regards

Rahul

1 Solution

Accepted Solutions
Not applicable
Author

ok, there is no any issue of inline, i had provide only the sample, you load table 1 according to you.like this

table1:

LOAD

    Customerid,

supplierid,

projectstatus

from table1;

RESULT:

lOAD

Customerid as customerid_new,

projectstatus as projectstatus_new,

SubField(supplierid,',',ITERNO()) AS supplierid_new

RESIDENT table1

WHILE(ITERNO()<=SubStringCount(supplierid,',')+1);

table2:

LOAD

supplierid as supplierid_new

article,

spend

from table2;

View solution in original post

10 Replies
sujeetsingh
Master III
Master III

Hi,

Try

subfield(SupllierID, ',' ,1)  it will give you 1 from value 1,2,3

subfield(SupllierID, ',' ,2)  it will give you 2 from value 1,2,3

so use this logic and try it or try giving a sample to us.

Not applicable
Author

Hi

Thanks for your reply.

Enclosed is the example.

But the supplier id can be different. here i have shown just an example.

is it possible it takes data from table 1 for such logic.

Not applicable
Author

TABLE1:

    CustomerID, SupplierID

    from table1

RESULT:

lOAD

CustomerID,

SubField(SupplierID,',',ITERNO()) AS SupplierID

RESIDENT TABLE1

WHILE(ITERNO()<=SubStringCount(SupplierID,',')+1);

TABLE2:

LOAD

SupplierID,Article,Spend

from table2;

Not applicable
Author

firstly make table1 as given below.

table1:

LOAD * INLINE [

    Customerid, supplierid, projectstatus

    123, 2, green

    145, "1,4,6,7", yello

    167, "3,8,9", red

];

RESULT:

lOAD

Customerid as customerid_new,

projectstatus as projectstatus_new,

SubField(supplierid,',',ITERNO()) AS supplierid_new

RESIDENT table1

WHILE(ITERNO()<=SubStringCount(supplierid,',')+1);

Not applicable
Author

this is the correct code according to your requirement.

table1:

LOAD * INLINE [

    Customerid, supplierid, projectstatus

    123, 2, green

    145, "1,4,6,7", yello

    167, "3,8,9", red

];

RESULT:

lOAD

Customerid as customerid_new,

projectstatus as projectstatus_new,

SubField(supplierid,',',ITERNO()) AS supplierid_new

RESIDENT table1

WHILE(ITERNO()<=SubStringCount(supplierid,',')+1);

table2:

LOAD supplierid as supplierid_new,* INLINE [

    supplierid, article, spend

    1, 1234, 100,

    1, 1344, 100,

    1, 1454, 100,

    2, 1564, 100,

    2, 1674, 100,

    3, 1784, 100,

    3, 1894, 100,

    4, 2004, 100,

    5, 2114, 100,

    6, 2224, 100,

    6, 2334, 100,

    7, 2444, 100,

    7, 2554, 100,

    8, 2664, 100,

    9, 2774, 100,

    9, 2884, 100

];

drop Table table1;

then output like this

supplierid_newcustomerid_newprojectstatus_newarticlespend
1145yello1234100
1145yello1344100
1145yello1454100
2123green1564100
2123green1674100
3167red1784100
3167red1894100
4145yello2004100
5 2114100
6145yello2224100
6145yello2334100
7145yello2444100
7145yello2554100
8167red2664100
9167red2774100
9167red2884100
sujeetsingh
Master III
Master III

You can refer this ....

Not applicable
Author

Dear Vishwaran

Thanks for your reply.

But my table cannot be an inline table. This is just a sample data.

Table 1 will be taken directly from the server.

the supplier id in table 1 can change during each reload.

Request your views.

Not applicable
Author

Hi SOS,

Thanks for your reply.

But my table cannot be an inline table. This is just a sample data.

Table 1 will be taken directly from the server.

the supplier id in table 1 can change during each reload.

Request your views.

Not applicable
Author

ok, there is no any issue of inline, i had provide only the sample, you load table 1 according to you.like this

table1:

LOAD

    Customerid,

supplierid,

projectstatus

from table1;

RESULT:

lOAD

Customerid as customerid_new,

projectstatus as projectstatus_new,

SubField(supplierid,',',ITERNO()) AS supplierid_new

RESIDENT table1

WHILE(ITERNO()<=SubStringCount(supplierid,',')+1);

table2:

LOAD

supplierid as supplierid_new

article,

spend

from table2;