Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Data mapping condition in script

Lets say I have two tables looks like below

Table 1

IDProductAmount
1A100
1B200

Table2

IDProductAmount
1A300
1C250

Now I want to create the Final table with below condition

If ID & Product from Table1 exist in Table2 , then Take the Amount wherever it is greater, in this case it will pick from table2.

Also take ID & Product from Table2 which not there in Table1.

Final Output

  

IDProductAmount
1A300
1B200
1C250
1 Solution

Accepted Solutions
Kushal_Chawda

Give it a try


Map:

mapping LOAD

    Autonumber(ID&Product) as Key,

    Amount

FROM Table2;

Data1:

LOAD ID,

    Product,

    Autonumber(ID&Product) as Key,

    rangemax(applymap('Map',Autonumber(ID&Product)),Amount) as Amount

FROM Table1;

concatenate(Data1)

LOAD *

where not exists(Key);

LOAD ID,

    Product,

    Amount,

    Autonumber(ID&Product) as Key

FROM Table2;

Drop Field Key;

View solution in original post

30 Replies
Kushal_Chawda

try something like below

Data1:

LOAD ID,

     Product,

     Autonumber(ID&Product) as Key

     Amount

FROM table1;

Data2:

noconcatenate

LOAD ID,

     Product,

     Autonumber(ID&Product) as Key

     Amount as Amount1

FROM table2;

left join(Data1)

LOAD Key,

     Amount1

Resident Data2

where exists(Key);

concatenate(Data1)

LOAD *

Resident Data2

where not exists(Key);

drop table Data2;

Final:

noconcatenate

LOAD *,

     if(Amount1>Amount,Amount1,Amount) as FinalAmount

Resident Data1;

drop table Data1;

avinashelite

try like this

Temp:

Mapping LOAD ID&'-'&Product as Key,

Amount

from Table 1;

Result:

LOAD ID&'-'&Product as Master_Key,

ID,

Product ,

if(Applymap('Temp',ID&'-'&Product,Amount)>Amount, Amount, Applymap('Temp',ID&'-'&Product,Amount) as Amount

from Table  2;


LOAD ID,

Product,

Amount

from Table 2

where not exist(Master_Key,ID&'-'&Product);



tamilarasu
Champion
Champion

You can also try,

A:

LOAD ID,

    Product,

    Amount

FROM Table1;

Concatenate

LOAD ID,

    Product,

    Amount

FROM Table2;

Inner Join (A)

Load ID,

Product,

Max(Amount) as Amount

Resident A Group by ID, Product;

jonathandienst
Partner - Champion III
Partner - Champion III

That is what I would so. Simple and effective.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Hi,

I've attached script where after you loaded the 2 data tables, you can use the create the following table to show the desired result

NoConcatenate

Result:

Load

  ID,

  Product,

  Amount,

  autonumber(RecNo() , Product)

Resident

  Table

Where

  autonumber(RecNo() , Product) = 1

Order by

  Product, Amount desc;

Not applicable
Author

Don't you think that if amount of data is huge in this case max with group may cause the performance issue?

Not applicable
Author

This group by method consuming more RAM as compared to other's solution as amount of data is huge.

tamilarasu
Champion
Champion

Fine. Check the below script.

A:

LOAD ID,

     Product,

     Amount

FROM

Table1;

Concatenate

LOAD ID,

     Product,

     Amount

FROM

Table2;

Store A into A.qvd (qvd);

DROP Table A;

Data:

LOAD ID,

     Product,

     FirstSortedValue(Amount,-Amount) as Amount

FROM

A.qvd

(qvd) Group By ID, Product

sunny_talwar

Yet another option to test out:

Table:

LOAD ID,

    Product,

    Amount

FROM

[https://community.qlik.com/thread/215061]

(html, codepage is 1252, embedded labels, table is @1);

Concatenate(Table)

LOAD ID,

    Product,

    Amount

FROM

[https://community.qlik.com/thread/215061]

(html, codepage is 1252, embedded labels, table is @2);

FinalTable:

NoConcatenate

LOAD ID,

  Product,

  Amount

Resident Table

Where ID&Product <> Previous(ID&Product)

Order By ID, Product, Amount desc;

DROP Table Table;


Capture.PNG