Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
jeff_k
Contributor
Contributor

What functions in data load script should I use on these two tables? for Vehicle sales transactions

I am working on two tables that represents the list of orders and another table that represents the extra features customers ordered on each of those transactions. I can think of using multiple ApplyMaps, but is there any better way to do this?

Table A looks like this:

OrderIdVehicleIdBasePrice
101110,000
102220,000
103330,000
104440,000
105550,000

 

Table B looks like this:

OrderIDExtraFeatureExtraFees
101Paint500
101FloorMat100
102Paint350
102Exhaust700
103Navigation1,500
103FloorMat200
103Paint600
104Wheels2,000
104Paint750
104Lights650
105Paint750

 

How do I get the final table to look like this:

OrderIdVehicleIdBasePricePaintFloorMatExhaustNavigationWheelsLights
101110,000500100----
102220,000350-700---
103330,000600200-1,500--
104440,000750---2,000650
105550,000750-----
1 Solution

Accepted Solutions
stevejoyce
Specialist II
Specialist II

Check out "generic load".  there's a post solving this requirement:

The Generic Load - Qlik Community - 1473470

it will unpivot ExtraFeature, by default each distinct ExtraFeature will go into its own table, which on its own will give you what you want.  But less efficient on memory but cleaner is to match your single larger table you can also add a for loop + join.  I like to work from highest table number backwards instead of the article, this is what i would do.

 


tableB:
generic load
OrderID, ExtraFeature, ExtraFees
;
tableB:
load distinct * inline [
OrderID, ExtraFeature, ExtraFees
101, Paint, 500
101, FloorMat, 100
102, Paint, 350
102, Exhaust, 700
103, Navigation, 1500
103, FloorMat, 200
103, Paint, 600
104, Wheels, 2000
104, Paint, 750
104, Lights, 650
105, Paint, 750
]

;

let vNumberOfTables = NoOfTables();

For vTableNo = 0 to $(vNumberOfTables)

Let vTableNo_new = $(vNumberOfTables)-$(vTableNo);
Let vTableName = TableName($(vTableNo_new)) ;

Trace WORKING ON TABLE $(vTableNo_new);

If Subfield(vTableName,'.',1)='tableB' Then

Trace CREATED IN GENERIC LOAD. JOIN AND DROP;


Left Join ('tableA')
Load *
Resident [$(vTableName)];

Drop Table [$(vTableName)];

End If

Next vTableNo

SET vNumberOfTables =;

View solution in original post

3 Replies
stevejoyce
Specialist II
Specialist II

Check out "generic load".  there's a post solving this requirement:

The Generic Load - Qlik Community - 1473470

it will unpivot ExtraFeature, by default each distinct ExtraFeature will go into its own table, which on its own will give you what you want.  But less efficient on memory but cleaner is to match your single larger table you can also add a for loop + join.  I like to work from highest table number backwards instead of the article, this is what i would do.

 


tableB:
generic load
OrderID, ExtraFeature, ExtraFees
;
tableB:
load distinct * inline [
OrderID, ExtraFeature, ExtraFees
101, Paint, 500
101, FloorMat, 100
102, Paint, 350
102, Exhaust, 700
103, Navigation, 1500
103, FloorMat, 200
103, Paint, 600
104, Wheels, 2000
104, Paint, 750
104, Lights, 650
105, Paint, 750
]

;

let vNumberOfTables = NoOfTables();

For vTableNo = 0 to $(vNumberOfTables)

Let vTableNo_new = $(vNumberOfTables)-$(vTableNo);
Let vTableName = TableName($(vTableNo_new)) ;

Trace WORKING ON TABLE $(vTableNo_new);

If Subfield(vTableName,'.',1)='tableB' Then

Trace CREATED IN GENERIC LOAD. JOIN AND DROP;


Left Join ('tableA')
Load *
Resident [$(vTableName)];

Drop Table [$(vTableName)];

End If

Next vTableNo

SET vNumberOfTables =;

jeff_k
Contributor
Contributor
Author

thank you! this is exactly what i need!

stevejoyce
Specialist II
Specialist II

Great! Please mark the thread complete if this has answered your question.