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

Left Join - very unique!!

HI All!

i have a sales table like follow - very simple: Date/Customer/Item/Amount

qlikviewaf_1-1619101207364.png

Then i have another table that i wolud like to left join based on Customer+Item+Date , in order to assign the value "Gara" to the sales table.

qlikviewaf_3-1619101532806.png

For each line on sales table i would like to assign just one line of the second table.

This is the result i would like to achieve. The left join should occur based on customer and item, but also looking the date. Assign value "Gare" only if date is equal or greater to Date(on sales table) - then if for the same item&customer a new record exist on the second table, the most recent needs to be applied just from that specific date on.

To better clarify, here is the result i would like to get. I tried something on the Qvw attached but didnt get what i want.

Anyone can please help? Thanks!

DateCustomerItemAmountGara
01/02/2021LizA100 
02/03/2021LizA2001291
02/03/2021LizA3001291
22/03/2021LizA4001291
11/04/2021LizD5001291
01/05/2021LizD500TESI9
21/05/2021LizD500TESI9
01/02/2021TonyA100 
02/03/2021TonyA200 
02/03/2021TonyA300 
22/03/2021TonyA400 
20/04/2021TonyZ500TEST
10/05/2021TonyZ500ABORS
30/05/2021TonyZ500ABORS

 

 

1 Solution

Accepted Solutions
MayilVahanan

Hi @qlikviewaf 

For Item D for Liz, there is no offering info, then how you were mapped with Gara?

MayilVahanan_0-1619165718945.png

If you've missed the offer for D, then try like below

Sales:
LOAD Date,Customer, Item, Amount, Customer&Item as Key
FROM [Sales Data Gare.xlsx]
(ooxml, embedded labels, table is Sales);

Offering:
LOAD
Customer&Item as Key,
Date,
Gara
FROM
[D:\Qlik\Com\Sales Data Gare.xlsx]
(ooxml, embedded labels, table is Offering);

OfferingTemp:
Load Key, Date as StartDate, Gara, If(Key = Previous(Key), Date(Peek('StartDate')-1), Date(Yearend(Today()))) as EndDate Resident Offering
order by Key, Date desc;


DROP Table Offering;

Final:
IntervalMatch(Date, Key)
Load StartDate, EndDate, Key Resident OfferingTemp;

Join(Final)
LOAD * Resident Sales;

Left Join(Final)
Load * Resident OfferingTemp;

DROP Table OfferingTemp, Sales;

 

o/p:

MayilVahanan_1-1619165936604.png

 

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

2 Replies
edwin
Master II
Master II

the rule re the dates is a bit confusing.  my understanding is to find the newest date from table 2 for the same Customer and Item

however in your desired output, 01/02/2021 does not have a Gara found for it.

MayilVahanan

Hi @qlikviewaf 

For Item D for Liz, there is no offering info, then how you were mapped with Gara?

MayilVahanan_0-1619165718945.png

If you've missed the offer for D, then try like below

Sales:
LOAD Date,Customer, Item, Amount, Customer&Item as Key
FROM [Sales Data Gare.xlsx]
(ooxml, embedded labels, table is Sales);

Offering:
LOAD
Customer&Item as Key,
Date,
Gara
FROM
[D:\Qlik\Com\Sales Data Gare.xlsx]
(ooxml, embedded labels, table is Offering);

OfferingTemp:
Load Key, Date as StartDate, Gara, If(Key = Previous(Key), Date(Peek('StartDate')-1), Date(Yearend(Today()))) as EndDate Resident Offering
order by Key, Date desc;


DROP Table Offering;

Final:
IntervalMatch(Date, Key)
Load StartDate, EndDate, Key Resident OfferingTemp;

Join(Final)
LOAD * Resident Sales;

Left Join(Final)
Load * Resident OfferingTemp;

DROP Table OfferingTemp, Sales;

 

o/p:

MayilVahanan_1-1619165936604.png

 

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.