Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
govind1501
Contributor III
Contributor III

Help me to derive new field in one table using the existing field in other table.

Hi All, Can you please help us on below requirement.

I have two tables Customer and Priority.

Customer table is the master table, now i need to get the new fields/columns (High and Low) in the customer table using the existing field/column 'Priority' in the priority table. Also  we need to make sure to not increase the row count in customer table as it is the master/fact table in data model. Please find sample data and expected output below and advise me the approach please.

Customer Table:

EmpCountryStatus
101IndiaOpen
102SrilankaClosed
103AustraliaOpen
104EnglandClosed
105EnglandOpen
106IndiaClosed
107BangladeshOpen

 

Priority Table:

EmpCountryPriority
101IndiaHigh
101IndiaLow
102SrilankaLow
103AustraliaHigh
103AustraliaLow
104EnglandLow
105EnglandHigh

 

Expected output:

EmpCountryStatusHighLow
101IndiaOpenYN
102SrilankaClosedNY
103AustraliaOpenYY
104EnglandClosedYY
105EnglandOpenYN
106IndiaClosedN/AN/A
107BangladeshOpenN/AN/A

 

Thanks

Labels (3)
1 Solution

Accepted Solutions
Taoufiq_Zarra

Hi,

I propose you this solution

Attached the Qlikview File

the Script:

 

Data:

load * inline [
Emp,Country,Status
101,India,Open
102,Srilanka,Closed
103,Australia,Open
104,England,Closed
105,England,Open
106,India,Closed
107,Bangladesh,Open
];

join

load * inline [
Emp,CountryN,Priority
101,India,High
101,India,Low
102,Srilanka,Low
103,Australia,High
103,Australia,Low
104,England,Low
105,England,High
];

Hight:

load Emp,Country,Status,'Y' as High resident Data where Priority='High';

join

load Emp,Country,Status,'Y' as Low resident Data where Priority='Low';
join
load Emp,Country,Status,'N/A' as High,'N/A' as Low resident Data where len(Priority)=0;

drop table Data;

 

and the output :

Capture.PNG

the null values correspond to the values not filled.

for example 105 England High exist and 105 England Low does not exist in the source table.

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

4 Replies
Taoufiq_Zarra

Hi,

I propose you this solution

Attached the Qlikview File

the Script:

 

Data:

load * inline [
Emp,Country,Status
101,India,Open
102,Srilanka,Closed
103,Australia,Open
104,England,Closed
105,England,Open
106,India,Closed
107,Bangladesh,Open
];

join

load * inline [
Emp,CountryN,Priority
101,India,High
101,India,Low
102,Srilanka,Low
103,Australia,High
103,Australia,Low
104,England,Low
105,England,High
];

Hight:

load Emp,Country,Status,'Y' as High resident Data where Priority='High';

join

load Emp,Country,Status,'Y' as Low resident Data where Priority='Low';
join
load Emp,Country,Status,'N/A' as High,'N/A' as Low resident Data where len(Priority)=0;

drop table Data;

 

and the output :

Capture.PNG

the null values correspond to the values not filled.

for example 105 England High exist and 105 England Low does not exist in the source table.

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Kushal_Chawda

try with applymap approach instead of join

High_Map:
mapping LOAD Distinct
    Emp&Country as Key,
    'Y' as High
FROM [lib://Qlik web]
(html, utf8, embedded labels, table is @2)
where Priority='High';

Low_Map:
mapping LOAD Distinct
    Emp&Country as Key,
    'Y' as Low
FROM [lib://Qlik web]
(html, utf8, embedded labels, table is @2)
where Priority='Low';

T1:
Load Emp,
     Country,
     Status,
     if(match(Low,'Y','N') and High='NA','N',High) as High,
     if(match(High,'Y','N') and Low='NA','N',Low) as Low;
LOAD
    Emp,
    Country,
    ApplyMap('High_Map',Emp&Country,'NA') as High,
    ApplyMap('Low_Map',Emp&Country,'NA') as Low,    
    Status
FROM [lib://Qlik web]
(html, utf8, embedded labels, table is @1);

govind1501
Contributor III
Contributor III
Author

Both the solutions are working. Thank you MVP for providing optimized solution... Currently i am using joins in first place and will implement your solution in optimization... 

Kushal_Chawda

You should avoid using joins and always implement optimised solution. But it's up to you.

https://community.qlik.com/t5/Qlik-Design-Blog/Don-t-join-use-Applymap-instead/ba-p/1467592