Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
j_fulcher
Partner - Contributor
Partner - Contributor

Lookup query

Hi All,

I am experimenting with Lookup() in the load script of an app i'm working on and have an issue. My data has this form:

YearIDPeerIDSalesPeer Sales
20101_11_1110110
20101_21_2320320
20101_31_3250250
20102_11_1600110
20111_11_1540540
20111_21_2130130
20111_31_3270270
20112_11_1820540
20113_11_1560540

 

The red column is the field I am hoping to produce in Qlik.

I have used the following:

 

lookup('Sales','ID',PeerID) as [PeerSales]

 

Unfortunately this always looks for the first value with the correct value of ID and therefore does not always lookup data in the same accident year. Is there a way to only look for values within a specified range of the data, i.e. only in the correct 'Year'?

 

Thanks in advance for any help

 

1 Solution

Accepted Solutions
sunny_talwar

Try this

Table:
LOAD RowNo() as RowNum,
	 *;
LOAD * INLINE [
    Year, ID, PeerID, Sales
    2010, 1_1, 1_1, 110
    2010, 1_2, 1_2, 320
    2010, 1_3, 1_3, 250
    2010, 2_1, 1_1, 600
    2011, 1_1, 1_1, 540
    2011, 1_2, 1_2, 130
    2011, 1_3, 1_3, 270
    2011, 2_1, 1_1, 820
    2011, 3_1, 1_1, 560
];

Left Join (Table)
LOAD Year,
	 ID as PeerID,
	 Sales as PeerSales
Resident Table;

View solution in original post

2 Replies
sunny_talwar

Try this

Table:
LOAD RowNo() as RowNum,
	 *;
LOAD * INLINE [
    Year, ID, PeerID, Sales
    2010, 1_1, 1_1, 110
    2010, 1_2, 1_2, 320
    2010, 1_3, 1_3, 250
    2010, 2_1, 1_1, 600
    2011, 1_1, 1_1, 540
    2011, 1_2, 1_2, 130
    2011, 1_3, 1_3, 270
    2011, 2_1, 1_1, 820
    2011, 3_1, 1_1, 560
];

Left Join (Table)
LOAD Year,
	 ID as PeerID,
	 Sales as PeerSales
Resident Table;
j_fulcher
Partner - Contributor
Partner - Contributor
Author

Thanks, this has done exactly what I needed!