Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Load, merge two source files and create a new field in the merged table

I'm pretty new to the Qlikview desktop product and have a need to write a script to create a QVD that will

1. Merge one database file and one Excel file based on a common key "AccountNumber"

2. Create a new column "CalcAmount" in the merged table

if "PaidAmount" <> 0

set CalcAmount = PaidAmount

else

set Calc Amount = SalesAmount

Two source files and the columns in each table are:

1) Table_Sales from a database

* AccountNumber

* SalesAmount

2) Table_Paid from an Excel file

* AccountNumber

* PaidAmount

Examples:

1) Table_Sales

AccountNumber SalesAmount

A 1000

B 1000

C 500

D 700

2) Table_Paid

AccountNumber PaidAmount

A 0

B 999

C -100

3) Merged_Table

AccountNumber SalesAmount PaidAmount CalcAmount

A 1000 0 1000

B 1000 999 999

C 500 -100 -100

D 700 0 700

Any help on the best approach to solve this problem will be greatly appreciated. Thanks

1 Solution

Accepted Solutions
johnw
Champion III
Champion III

Something along these lines:

Data:
LOAD
AccountNumber
,SalesAmount
FROM your database
;
OUTER JOIN (Data) // Or left join if sale must exist
LOAD
AccountNumber
,PaidAmount
FROM your Excel file
;
LEFT JOIN (Data)
LOAD *
,if(PaidAmount,PaidAmount,SalesAmount) as CalcAmount
RESIDENT Data
;

STORE Data INTO Data.qvd (QVD);

View solution in original post

2 Replies
johnw
Champion III
Champion III

Something along these lines:

Data:
LOAD
AccountNumber
,SalesAmount
FROM your database
;
OUTER JOIN (Data) // Or left join if sale must exist
LOAD
AccountNumber
,PaidAmount
FROM your Excel file
;
LEFT JOIN (Data)
LOAD *
,if(PaidAmount,PaidAmount,SalesAmount) as CalcAmount
RESIDENT Data
;

STORE Data INTO Data.qvd (QVD);

Anonymous
Not applicable
Author

It works like a champ! Cool Thank you John.