Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Add field to every record in table based on one record in group

I have a table similar to below.  I would like to append a field (Master_Product_Id)  into the table on load that looks by Location for a Master_Product = TRUE by Location and adds the Product_Id of the Master_Product to every Product at each Location.  Is ok if it adds it to the Master_Product as well, but that is not how it is displayed below.

LocationProductProduct_IdMaster_ProductMaster_Product_Id
Bobapple1234aFALSE3376t
Boborange2765wTRUE
Bobmelon3376tFALSE3376t
Jenpaper3986jTRUE
Jenpen6439hFALSE3986j
Jenpencil9823gFALSE3986j
Jencup7756mFALSE9577t
Mary bike2213rFALSE9577t
Mary car9577tTRUE

1 Solution

Accepted Solutions
maxgro
MVP
MVP

a:

load Location, Product, Product_Id, Master_Product inline [

Location, Product, Product_Id, Master_Product, Master_Product_Id

Bob, apple, 1234a, FALSE, 2765w

Bob, orange, 2765w, TRUE,

Bob, melon ,3376t, FALSE, 2765w

Jen, paper, 3986j, TRUE,

Jen, pen, 6439h, FALSE, 3986j

Jen, pencil, 9823g, FALSE, 3986j

Jen, cup, 7756m, FALSE, 3986j

Mary, bike, 2213r, FALSE, 9577t

Mary, car, 9577t, TRUE,

];

left join (a)

load

  Location,

  Product_Id as Master_Product_Id

resident a

Where Master_Product = 'TRUE';

1.jpg

View solution in original post

5 Replies
Anonymous
Not applicable
Author

Help if I made the example correct in the first place...

LocationProductProduct_IdMaster_ProductMaster_Product_Id
Bobapple1234aFALSE2765w
Boborange2765wTRUE
Bobmelon3376tFALSE2765w
Jenpaper3986jTRUE
Jenpen6439hFALSE3986j
Jenpencil9823gFALSE3986j
Jencup7756mFALSE3986j
Mary bike2213rFALSE9577t
Mary car9577tTRUE

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

If I understand correctly, you want it to happen in the load script, right? Load a temporary table with all the Master products by Location and then join it back to the main table:

temp:

load

     Location,

     Product_Id as Master_Product_Id

resident

     Table

where

     Master_Product = 'TRUE'

;

left join (Table)

load *

resident temp;

drop table temp;

maxgro
MVP
MVP

a:

load Location, Product, Product_Id, Master_Product inline [

Location, Product, Product_Id, Master_Product, Master_Product_Id

Bob, apple, 1234a, FALSE, 2765w

Bob, orange, 2765w, TRUE,

Bob, melon ,3376t, FALSE, 2765w

Jen, paper, 3986j, TRUE,

Jen, pen, 6439h, FALSE, 3986j

Jen, pencil, 9823g, FALSE, 3986j

Jen, cup, 7756m, FALSE, 3986j

Mary, bike, 2213r, FALSE, 9577t

Mary, car, 9577t, TRUE,

];

left join (a)

load

  Location,

  Product_Id as Master_Product_Id

resident a

Where Master_Product = 'TRUE';

1.jpg

Anonymous
Not applicable
Author

Thank you Massimo.

Anonymous
Not applicable
Author

Thank you Oleg.