Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

one to many relationship - distinct output

Hello community,

I'm new in Qlikview, I need a suggestion about loading two tables with one-to- many relationship and obtain in output one table with no rows duplicated and new coloumns.I have a table A of customers and table B of orders of only two products. I need an output table with two new columns in order to indicate if a customer has purchased ProductA, ProductB or both.

Table A: Costumers

ID_customerCustomerNameAddress
1Customer1Address1
2Customer2Address2
3Customer3Address3

Table 2: Orders

ID_customerID_ProductDate of purchase
1ProductA20/03/2017 09.00
1ProductA25/03/2017 09.35
1ProductB24/03/2017 17.38
2ProductA09/03/2017 15.45

output:

ID_customerCustomerNameAddress1ProductA

ProductB

1Customer1Address1YY
2Customer2Address2YN
3Customer3Address3NN

Thank you for your advice

4 Replies
stephenedberkg
Creator II
Creator II

Hi,

Try this

T1:

LOAD ID_customer,

     CustomerName,

     Address

FROM

(ooxml, embedded labels, table is Sheet1);

Left Join

T2:

LOAD ID_customer,

     ID_Product,

     [Date of purchase]

FROM

(ooxml, embedded labels, table is Sheet2);

T3:

LOAD

  ID_customer,

     CustomerName    ,

    

     Address ,

    ID_Product,

    If(ID_Product = 'ProductA','Y','N' ) as ProductA,

     If(ID_Product =  'ProductB' ,'Y','N') as  ProductB,

[Date of purchase]

  

Resident T1;

DROP Table T1;

Not applicable
Author

Hi Stephen,

thank you for your feedback.

If I run your code I obtain duplicated rows in T3 table.

For example

ID_customerCustomerNameAddress1ProductA

ProductB

1Customer1Address1YN
1Customer1Address1NY

Is there a way to merge the rows?

Thanks,

Flavio

Not applicable
Author

Hi,

The output table shows the data of the customer's purchase on different dates.

Since A has purchased 3 products on three different dates, data related to A's purchase has appeared.

It is not duplicated.

Not applicable
Author

Hello,

yes you are right, but is there a way to aggregate the data ? I'd like only to know if a costumer has ever purchased a kind of product so the output table should be for example for costumer 1

1Customer1Address1YY

Thanks in advance,

Flavio