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

Load if isnull in Load Script (sub/inner load)

Hei everybody,

i am new at qlik sense and i need to do something like a sub/inner load (maybe with a join or a for each but i dont know whats the best way and how to do it). 

That is the current Situation:

I want to create a table with the state of every customer for every day (not just today).

Therefore I need to calculate the state for everyone an every day. If a customer place an order within the last 12 months he/she is active, else inactive

I have 3 tables: Customer, Order and Date 

Customer:

Customer
A
B

 

Order:

IDDateCustomer
111.1.2019A
221.1.2019B
332.1.2019A

 

Date:

Date
1.1.2019
2.1.2019
3.1.2019
1.1.2020
2.1.2020
3.1.2020

 

One problem is, that not everybody place an order on everyday but i need the customerstate for every day und every customer. To solve this, I do a cross join on Customer and Date to get the following table:

table1:

DateCustomer
1.1.2019A
1.1.2019B
2.1.2019A
2.1.2019B
3.1.2019A
3.1.2019B
1.1.2020A
1.1.2020B
2.1.2020A
2.1.2020B
3.1.2020A
3.1.2020B

 

Now I need to calculate the state for every row. I thought about 2 ways:

Join: I can do a join between the tables 'order' and 'table1' but then I have many missing values and I dont know how to calculate the state of them (how to check if there is an order within the last 12 months). 

tableJoin:

DateCustomerOrder
1.1.2019A11
1.1.2019B22
2.1.2019A33
2.1.2019B 
3.1.2019A 
3.1.2019B 
1.1.2020A 
1.1.2020B 
2.1.2020A 
2.1.2020B 
3.1.2020A 
3.1.2020B 

 

For: something like "for each row" but i have Millions of rows.... So there might be a problem with the calculation time.

The final result should look like:

tablefinal :

DateCustomerState
1.1.2019Aactive
1.1.2019Bactive
2.1.2019Aactive
2.1.2019Bactive
3.1.2019Aactive
3.1.2019Bactive
1.1.2020Aactive
1.1.2020Bactive
2.1.2020Aactive
2.1.2020Binactive
3.1.2020Ainactive
3.1.2020Binactive

 

I hope the description is understandable. 

 

Greets,

kotorbe

2 Replies
Taoufiq_Zarra

@kotorbe 

can you indicate :

the input table and the expected output ?

the initial input

Regards,
Taoufiq ZARRA

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

(you can mark up to 3 "solutions") 😉
kotorbe
Contributor
Contributor
Author

Input tables:

Date
(all dates between 01.01.2017 and today are included)
(just a few dates are shown below)

Date:
LOAD * Inline [
Date
'01.01.2020'
'02.01.2020'
'03.01.2020'
'04.01.2020'
'05.01.2020'
'06.01.2020'
'07.01.2020'
'08.01.2020'
];

Order
(all orders with orderdate and customerID since 2017 are included)
(just a few orders are shown below)

Order:
LOAD * Inline [
Date ,OrderID ,Customer
'01.01.2019' ,11 ,A
'02.01.2019' ,22 ,B
];

Expected Output:

Date              Customer  State
01.01.2020 A                    active
01.01.2020 B                    active
02.01.2020 A                    inactive
02.01.2020 B                    active
03.01.2020 A                    inactive
03.01.2020 B                    inactive

active: at least 1 Order within the last 12 months (current day included)
inactive: all other