Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
FFBB1983
Contributor III
Contributor III

Match the price to unit

Dear Community,

I have the sales report from the warehouses. I can find how many units of product got sold from there.

In order to get the revenue, I need to match the price to the unit sales for different provinces and different period of time. We have different price in different province and increased price once a while. This makes me find it is hard to match the price against the unit sales.

I have the source files look like this,

Price log,

PROVINCEADJ_PRICESTART_MTHEND_MTH
BC465.6201706201903
BC476.77201904 
AB470.4201704201903
AB479.81201904 
SK470.4201804201903
SK479.81201904 
ON460.8201704201711
ON465.6201712201805
ON470.4201806201904
ON479.81201905 
YT465.6201704201903
NU465.6201704201903

 

Unit Sales Report

DateCustomer ProvinceTransaction TypeUnits Sold/Returned
4/4/2016ON Sales1
4/15/2016BC Sales1
4/17/2016ON Sales1
4/28/2016AB Sales1
5/5/2016ON Sales5
5/6/2016ON Sales1
5/8/2016ON Sales1
5/24/2016ON Sales1
5/24/2016ON Sales1
5/31/2016ON Sales1
6/2/2016ON Sales2
6/2/2016ON Sales2
6/10/2016ON Sales2
6/10/2016SK Sales1
6/20/2016QCSales1
6/21/2016ON Sales1
6/23/2016QCSales1
7/1/2016ON Sales2
7/3/2016ON Sales4
7/4/2016NLSales2
7/9/2016BC Sales2
7/10/2016ON Sales1
7/13/2016ON Sales1
7/24/2016ON Sales1

 

Can anyone kindly take a look at this?

5 Replies
neelamsaroha157
Specialist II
Specialist II

 

You can create date from your YYYYMM fields as 

Date(MakeDate(Left(START_MTH,4), Right(START_MTH,2), 01), 'MM/DD/YYYY') as StartDate,
Date(If(Len(END_MTH)<1, Today(), MakeDate(Left(END_MTH,4), Right(END_MTH,2), 01)), 'MM/DD/YYYY') as EndDate

and then use interval match as

innerJoin(YourTable)
IntervalMatch(Date,PROVINCE)
LOAD StartDate, EndDate, PROVINCE Resident YourTable;

FFBB1983
Contributor III
Contributor III
Author

Thanks for your help. The IntervalMatch sounds about right. But I got two issues with those scripts,

1) Syntetic key got created,

2) I still cound not match the price against the unit sales in a given province and in a given time.

here are what I wrote,

LIB CONNECT TO 'Dropbox (#$$##@)';

PriceTable:
LOAD
PROVINCE,
ADJ_PRICE,
Date(MakeDate(Left(START_MTH,4), Right(START_MTH,2), 01), 'MM/DD/YYYY') as StartDate,
Date(If(Len(END_MTH)<1, Today(), MakeDate(Left(END_MTH,4), Right(END_MTH,2), 01)), 'MM/DD/YYYY') as EndDate

FROM [lib://Dropbox (#$$##@)/Qlik Case\Price increase log.xlsx]
(ooxml, embedded labels, table is Sheet1);

WMT:
LOAD
"Date",
"Customer Province",
"Transaction Type",
"Units Sold/Returned"

FROM [lib://Dropbox (#$$##@)/Qlik Case\Unit Sales Report.xlsx]
(ooxml, embedded labels, table is Sheet1);

Inner Join(WMT)
IntervalMatch(Date,PROVINCE)
LOAD StartDate, EndDate, PROVINCE
Resident PriceTable;

Can you please take look what else I still need to change?

 

clipboard_image_0.png

clipboard_image_1.png

 

neelamsaroha157
Specialist II
Specialist II

Sample1:
LOAD * INLINE [
PROVINCE ADJ_PRICE START_MTH END_MTH
BC 465.6 201706 201903
BC 476.77 201904
AB 470.4 201704 201903
AB 479.81 201904
SK 470.4 201804 201903
SK 479.81 201904
ON 460.8 201704 201711
ON 465.6 201712 201805
ON 470.4 201806 201904
ON 479.81 201905
YT 465.6 201704 201903
NU 465.6 201704 201903
](delimiter is ' ');


Table1:
NoConcatenate
LOAD PROVINCE,
ADJ_PRICE,
START_MTH,
END_MTH,
Date(MakeDate(Left(START_MTH,4), Right(START_MTH,2), 01), 'MM/DD/YYYY') as StartDate,
Date(If(Len(END_MTH)<1, Today(), MakeDate(Left(END_MTH,4), Right(END_MTH,2), 01)), 'MM/DD/YYYY') as EndDate
Resident Sample1;
DROP Table Sample1;

Sample2:
LOAD * INLINE [
Date Customer Province Transaction Type Units Sold/Returned
4/4/2018 ON Sales 1
4/15/2018 BC Sales 1
4/15/2019 BC Sales 5
4/17/2018 ON Sales 1
1/1/2019 AB Sales 1
5/5/2018 ON Sales 5
5/6/2018 ON Sales 1
5/8/2017 ON Sales 1
5/24/2017 ON Sales 1
5/24/2017 ON Sales 1
5/31/2017 ON Sales 1
6/2/2017 ON Sales 2
6/2/2018 ON Sales 2
6/10/2018 ON Sales 2
6/10/2018 SK Sales 1
6/20/2018 QC Sales 1
6/21/2018 ON Sales 1
6/23/2018 QC Sales 1
7/1/2017 ON Sales 2
7/3/2017 ON Sales 4
7/4/2017 NL Sales 2
7/9/2017 BC Sales 2
7/10/2017 ON Sales 1
7/13/2017 ON Sales 1
7/24/2018 ON Sales 1
](delimiter is ' ');


Table2:
LOAD Date(Date, 'MM/DD/YYYY') as TxnDate,
[Customer Province] as PROVINCE,
[Transaction Type],
[Units Sold/Returned]
Resident Sample2;
DROP Table Sample2;


inner Join(Table1)
IntervalMatch(TxnDate,PROVINCE)
LOAD StartDate, EndDate, PROVINCE Resident Table1;

 

clipboard_image_0.png

FFBB1983
Contributor III
Contributor III
Author

Thanks neelamsaroha157.

I am able to connect to price to the unit now. But your script created a synthetic key. Is that ok to leave it? If I want to have it removed, what is the best way?

Also, I got an error msg when I add "[Units_Sold/Returned] * ADJ_PRICE AS TotalSales". The goal of this exercise is to apply various prices and to get the total revenue in $.

Can you please advise how to change the script and make it happen? Attached is the QVF. Much appreciated!

 

clipboard_image_0.png

clipboard_image_0.png

 

 

neelamsaroha157
Specialist II
Specialist II

Hello @FFBB1983 ,

You don't have both the fields in same table and hence cannot apply operations on them. You'll need to join the two table to get what you need. Try this out - 

Sample1:
LOAD * INLINE [
PROVINCE ADJ_PRICE START_MTH END_MTH
BC 465.6 201706 201903
BC 476.77 201904
AB 470.4 201704 201903
AB 479.81 201904
SK 470.4 201804 201903
SK 479.81 201904
ON 460.8 201704 201711
ON 465.6 201712 201805
ON 470.4 201806 201904
ON 479.81 201905
YT 465.6 201704 201903
NU 465.6 201704 201903
](delimiter is ' ');


Table1:
NoConcatenate
LOAD PROVINCE,
ADJ_PRICE,
START_MTH,
END_MTH,
Date(MakeDate(Left(START_MTH,4), Right(START_MTH,2), 01), 'MM/DD/YYYY') as StartDate,
Date(If(Len(END_MTH)<1, Today(), MakeDate(Left(END_MTH,4), Right(END_MTH,2), 01)), 'MM/DD/YYYY') as EndDate
Resident Sample1;
DROP Table Sample1;

Sample2:
LOAD * INLINE [
Date Customer Province Transaction Type Units Sold/Returned
4/4/2018 ON Sales 1
4/15/2018 BC Sales 1
4/15/2019 BC Sales 5
4/17/2018 ON Sales 1
1/1/2019 AB Sales 1
5/5/2018 ON Sales 5
5/6/2018 ON Sales 1
5/8/2017 ON Sales 1
5/24/2017 ON Sales 1
5/24/2017 ON Sales 1
5/31/2017 ON Sales 1
6/2/2017 ON Sales 2
6/2/2018 ON Sales 2
6/10/2018 ON Sales 2
6/10/2018 SK Sales 1
6/20/2018 QC Sales 1
6/21/2018 ON Sales 1
6/23/2018 QC Sales 1
7/1/2017 ON Sales 2
7/3/2017 ON Sales 4
7/4/2017 NL Sales 2
7/9/2017 BC Sales 2
7/10/2017 ON Sales 1
7/13/2017 ON Sales 1
7/24/2018 ON Sales 1
](delimiter is ' ');


Table2:
outer Join(Table1)
LOAD Date(Date, 'MM/DD/YYYY') as TxnDate,
[Customer Province] as PROVINCE,
[Transaction Type],
[Units Sold/Returned]
Resident Sample2;
DROP Table Sample2;


inner Join(Table1)
IntervalMatch(TxnDate,PROVINCE)
LOAD StartDate, EndDate, PROVINCE Resident Table1;

NoConcatenate
LOAD *, [Units Sold/Returned]*ADJ_PRICE as Rev Resident Table1;
DROP Table Table1;