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: 
tamilarasu
Champion
Champion

Load script help (lookup)

Hello,

I am trying to do a lookup function to get a value and need to have it in a new column. I have concatenated column and need to get price based on highest position number. See below for example.

Capture.PNG

If there is only one unique value in concatenated column (no need to check position column), then the price should be displayed as it is column output. But if there are multiple values (nneed to check the position column) and I need to show the value which has highest position number.

In the above screenshot, I have multiple values from 16th to 23 (Need to check the position column) and I need to show the output as 945.70 (highest position number 80).

I have attached excel file. Please guide.

1 Solution

Accepted Solutions
jagan
Luminary Alumni
Luminary Alumni

Hi,

Try this script

Data:

LOAD

  RowNo() AS RowNo,

  Year,

     Month,

     Sold,

     [Prod Number],

     Currency,

     [Order Number],

     Concate,

     Pos,

     price

FROM

[DB.xlsx]

(ooxml, embedded labels, table is Sheet1);

Temp:

LOAD

  Concate,

     Max(RowNo) AS RowNo

RESIDENT Data

GROUP BY Concate;

LEFT JOIN(Temp)

LOAD

  Concate,

  RowNo,   

     price AS New_Price

RESIDENT Data;

LEFT JOIN (Data)

LOAD

Concate,

New_Price

RESIDENT Temp;

DROP TABLE Temp;

Regards,

Jagan.

View solution in original post

6 Replies
jagan
Luminary Alumni
Luminary Alumni

Hi,

Try this script

Data:

LOAD

  RowNo() AS RowNo,

  Year,

     Month,

     Sold,

     [Prod Number],

     Currency,

     [Order Number],

     Concate,

     Pos,

     price

FROM

[DB.xlsx]

(ooxml, embedded labels, table is Sheet1);

Temp:

LOAD

  Concate,

     Max(RowNo) AS RowNo

RESIDENT Data

GROUP BY Concate;

LEFT JOIN(Temp)

LOAD

  Concate,

  RowNo,   

     price AS New_Price

RESIDENT Data;

LEFT JOIN (Data)

LOAD

Concate,

New_Price

RESIDENT Temp;

DROP TABLE Temp;

Regards,

Jagan.

Not applicable

Try this. Thoroughly unit test it.

Temp:

LOAD Year,

     Month,

     Sold,

     [Prod Number],

     Currency,

     [Order Number],

     Concate,

     Pos,

     price

FROM

DB.xlsx

(ooxml, embedded labels, table is Sheet1);

DIS_CNT:

LOAD

Concate,

Max(Pos) as Pos

Resident Temp Group By Concate;

Inner Join

LOAD

Concate,

Pos,

price

Resident Temp;

Tab1:

NoConcatenate

LOAD

*

Resident Temp;

Inner Join

LOAD

Concate,

price as [Output needed]

Resident DIS_CNT;

DROP Table Temp;

DROP Table DIS_CNT;

Regards,

KKR

Anonymous
Not applicable

PFA

maxgro
MVP
MVP

another one

b:

LOAD *

FROM DB.xlsx

(ooxml, embedded labels, table is Sheet1);

Left Join (b)

load

  Concate,

  FirstSortedValue(price, -Pos) as Output

Resident b

group by Concate;

1.png

Not applicable

Hi,

Please find the attached QVW.

jagan
Luminary Alumni
Luminary Alumni

Hi,

FirstSortedValue() will return Null value, if you have multiple values matching, so try to avoid using FirstSortedValue().  For this data this work, may be in realtime data this may fail.

Regards,

Jagan.