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

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to create line for every month (even when there is no transaction in that month)

Hi!

I am building QV app where we need information for every months last day's QTYOnHand and StandardCost information,
I can get this information from transaction table.

Here is example when everything works easily (using monthend-function and max(transaction number)), because every month had at least one transaction. Transaction table holds information for QtyOnHand & StdCost also.

ItemKey MonthEndDate QtyOnHand StdCost
101A|SE|1030 31.1.2009 20 45
101A|SE|1030 28.2.2009 25 40
101A|SE|1030 31.3.2009 27 42
101A|SE|1030 30.4.2009 11 38
101A|SE|1030 31.5.2009 8 35
101A|SE|1030 31.6.2009 20 36

In script I can get largest transaction number (tr_trnbr) for every month with this

QOH_SumTemp1:
load
ItemKey,
max(tr_trnbr) as max_trnbr,
MONTH_END_DATE
resident TransactionHistory
group by MONTH_END_DATE, ItemKey;

And when I know largest transaction number I can get QtyOnHand & STDCost with mapping tables.


My problem is born when there is one or more month without any transaction for one ItemKey.
I get then something like this

ItemKey MonthEndDate QtyOnHand StdCost
101A|SE|1030 31.1.2009 20 45
101A|SE|1030 31.3.2009 27 42
101A|SE|1030 30.4.2009 11 38
101A|SE|1030 31.6.2009 20 36

Now February and May line is not exist because there was not any transactions for these months in transaction table.
But I want to get also those months with values on QtyOnHand & StdCost from last month with value.

ItemKey MonthEndDate QtyOnHand StdCost
101A|SE|1030 31.1.2009 20 45
101A|SE|1030 28.2.2009 20 45 <-no transactions, then values from last month with transaction(s)
101A|SE|1030 31.3.2009 27 42
101A|SE|1030 30.4.2009 11 38
101A|SE|1030 31.5.2009 11 38<-no transactions, then values from last month with transaction(s)
101A|SE|1030 31.6.2009 20 36

In sheet object I can use expression with above function, but how I can "store" this information for QV-table.
I need these values in later calculations in the same QV application.

Thank you,

Harri

3 Replies
martin59
Specialist II
Specialist II

Hi,

Could you send an extract of your script to watch how you load datas ?

You can use peek() function in your load script to generate values based on last row.

boorgura
Specialist
Specialist

Not sure if this is the ideal solution - But once you have the data.

Do an outer join with all the monthend dates.

so that you will have the missing monthend dates but no values for them.

Then you can have a conditional statement like : if(isnull(), previous()) or something similar.

Not applicable
Author

Hi!

I see couple of answers already in this thread, but here is more information.

Here is an extract of the script

TrHist: //from here is all the data readed
...
tr_effdate,
date(tr_effdate,'YYYY-MM-DD') as CALDATE,
Year(tr_effdate) as TRANSACTIONYEAR,
Month(tr_effdate)as TRANSACTIONMONTH,
Day(tr_effdate) as TRANSACTIONDAY,
monthend(tr_effdate) as MONTH_END_DATE,
tr_type,
tr_trnbr, //transaction number

tr_begin_qoh, //quantity before transactiontr_qty_loc //transaction's change to quantity

ytr_price,
...

QOH_SumTemp1: // this table get's maximum transaction number / month
load
%%%ITEM_KEY,
max(tr_trnbr) as max_trnbr,
MONTH_END_DATE
resident TrHist
where (tr_type <> 'WO-CLOSE' and tr_type <> 'RJCT-WO')
group by MONTH_END_DATE,%%%ITEM_KEY;


QTY_OH_Map: // here we get change of the quantity in stock
Mapping
load
%%%ITEM_KEY &'|' & tr_trnbr as %%%mapkey ,
tr_begin_qoh + tr_qty_loc as QTY_OH
resident TrHist;

STD_Price_Map: // here we get transaction price
Mapping
load
%%%ITEM_KEY &'|' & tr_trnbr as %%%mapkey ,
tr_price
resident TrHist;

QOH_Sum:
load
// %%%ITEM_KEY & '|' & MONTH_END_DATE as QTY_KEY,
%%%ITEM_KEY,
MONTH_END_DATE,
applymap('QTY_OH_Map',%%%ITEM_KEY & '|' & max_trnbr,'N/A') as QTY_OH,
applymap('STD_Price_Map',%%%ITEM_KEY & '|' & max_trnbr,'N/A') as STD_COST
resident QOH_SumTemp1;

Drop table QOH_SumTemp1;


table QOH_Sum after the running of the script:

%%%ITEM_KEY MONTH_END_DATE QTY_OH STD_COST

101A|SE|1030 1.2.2009 0 49,64906496
101A|SE|1030 1.4.2009 0 63,54801089
101A|SE|1030 1.5.2009 2 23,55
101A|SE|1030 1.7.2009 2 735,6
101A|SE|1030 1.8.2009 1 613
101A|SE|1030 1.9.2009 1 711,08
101A|SE|1030 1.10.2009 0 662,04
101A|SE|1030 1.11.2009 4 613
101A|SE|1030 1.12.2009 3 735,6
101A|SE|1030 1.1.2010 2 662,04

Yours,

Harri