Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Scripting / Cartesian products and conditions

Hello,

Could you please help me to solve this problem? I guess this should be quite easy to do with some experience, but I'm quite a beginner in QlikView development.

Here is my problem

Source data

There are two source tables, with few fields

Table: TODAY

Fields: Customer, Country, Name

Table: HISTORIC

Fields: Date, Customer, Country, Qtty

In QV, I would like to get three tables

Table: DIMENSIONS

Fields: Id, Customer, Country

Comment: In this table, there should all possible couples (Customer/Country) from the source table TODAY and the source table HISTORIC and an appropriate Id

Table: TODAY

Fields: Id, Name

Comment: It is the Id that can be find in DIMENSIONS, and the name from the source table TODAY

Table: HISTORIC

Fields: Id, Date, Qtty

Comment: It should be the Cartesian product Id/Date, with all possible Id that can be found in DIMENSIONS and all Date that can be found in the source table HISTORIC. If there is no quantity for this couple, then the value for qtty should be '0' (otherwise, it is the value from the source table HISTORIC)

The creation of DIMENSIONS and TODAY is ok, but I really face problems with HISTORIC

I guess it should look like

- Create the Cartesian product Id/Date

- Add the field Qtty depending on the existence of the couple Id/Date in the source table HISTORIC

error loading image

Your help would be very invaluable for me!

Pierre

1 Solution

Accepted Solutions
johnw
Champion III
Champion III

Here's one way (untested):

LEFT JOIN (B)
LOAD Id, Quantity as TempQuantity
RESIDENT A
;
DROP TABLE A
;
LEFT JOIN (B)
LOAD Id, if(len(TempQuantity),TempQuantity,1) as Quantity
RESIDENT B
;
DROP FIELD TempQuantity
;

View solution in original post

5 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Pierre,

if you don't mind posting your script (or, even better, the whole QVW), we'd be able to show you how to tweak it to get what you need.

cheers,

Not applicable
Author

Hello

Yes you are right Stick out tongue

I have attached the basic .qvw file

I thank you a lot !

Pierre

Not applicable
Author

Hello,

Basically, the problem is the following

There is a table A with two fields : Id and Quantity:

Record 1 : Id1, 12

There is a table B with one field : Id

Record 1 : Id1

Record 2 : Id2

I would like to add a column in table B with the quantity found in A, or 1 if there is no correspondence

Then, table B would be :

Record 1 : Id1, 12

Record 2 : Id2, 1

Do you have any idea ?

Thanks

johnw
Champion III
Champion III

Here's one way (untested):

LEFT JOIN (B)
LOAD Id, Quantity as TempQuantity
RESIDENT A
;
DROP TABLE A
;
LEFT JOIN (B)
LOAD Id, if(len(TempQuantity),TempQuantity,1) as Quantity
RESIDENT B
;
DROP FIELD TempQuantity
;

Not applicable
Author

Hi John,

It perfectly works !

I thank you for having taken time to help me Smile

Pierre