Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
Can you please advice me right solution, how to realize "outer apply with top 1" in qliksense?
I have 2 tables in qvd files (Sales and Price list)
I need to get result table: Sales + Price on document date
1. Sales
Date | Nr | Product | Qty |
2023.02.28 | 0000000445 | Gas | 5 |
2023.03.14 | 0000000446 | Gas | 12 |
2023.03.25 | 0000000447 | Gas | 6 |
2. Price list
Date from | Product | Price |
2023.03.15 | Gas | 10.55 |
2020.01.01 | Gas | 07.15 |
in sql i can do next:
select
sales.date,
sales.nr,
sales.product,
sales.qty,
pricelist.price
from
sales
outer apply (
select top 1
pricelist.price
from
pricelist
where
pricelist.product = sales.product
and pricelist.date <= sales.date
) as pricelist
Result table by sql:
date | nr | product | qty | price |
2023.02.28 | 0000000445 | Gas | 5 | 10.55 |
2023.03.14 | 0000000446 | Gas | 12 | 07.15 |
2023.03.25 | 0000000447 | Gas | 6 | 07.15 |
but how to do same in qliksense?
left join or applymap with date condition?
@vv you can use intervalmatch like this
Data:
LOAD
"Date",
Nr,
Product,
Qty
FROM [lib://comm]
(html, utf8, embedded labels, table is @1);
price:
LOAD
"Date from",
Product,
Price
FROM [lib://comm]
(html, utf8, embedded labels, table is @2);
price_final:
Load *,
date(if(Product<>Previous(Product),Today(), Previous("Date from")-1)) as "Date to"
Resident price
Order by Product,"Date from" desc;
Drop Table price;
left Join(Data)
IntervalMatch ( "Date", Product )
LOAD "Date from", "Date to", Product
Resident price_final;
Left Join(Data)
Load * Resident price_final;
Drop Table price_final;
Drop Fields "Date from", "Date to";