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

Announcements
ALERT: QlikView server communication interruptions following Microsoft Windows Domain Controller security updates
cancel
Showing results for 
Search instead for 
Did you mean: 
inigoelv
Creator
Creator

DIVIDE VALUES PROPORTIONALLY TO THE AFFECTED MONTHS

The object of this discussion is whether there is any function that divides the values proportionally to the affected months.

Per example, if I have two waste

WasteQuantity TonInitial date of storageFinal date of storage
A1001/01/201215/03/2012
B2024/02/2001203/04/2012

What I want is to know the quantity generated per month or what is the same:

WasteJanuaryFebruaryMarchApril
A4,183,782,04
B2,1016,31,6

Thanks in advance,

Labels (1)
1 Solution

Accepted Solutions
inigoelv
Creator
Creator
Author

Hello:

At the end the solution was:

1) In the script to create a file by moth affected ans waste:

 

LOAD

[Waste],

[Quantity Ton],

[Initial date of storage],

[Final date of storage],

Date(AddMonths(MonthStart ([Initial date of storage]),iterno()-1),'MMMYYYY') as Month

FROM

(
ooxml, embedded labels, header is 3 lines, table is [Waste])while monthstart([Final date of storage]) >= addmonths(monthstart([Initial date of storage]),iterno

()-1);

2) In the espression:

=Sum ([Quantity Ton]/([Final date of storage]-[Initial date of storage]))*(If ([Initial date of storage]>=(MonthStart(Month)), MonthEnd (Month)-[Initial date of storage],
If([Final date of storage]<=(MonthEnd(Month)),[Final date of storage]-MonthStart(Month),
MonthEnd (Month)-MonthStart(Month))))

I hope it will be helpfull.

View solution in original post

4 Replies
nagaiank
Specialist III
Specialist III

The attached qvw file one way of implementing what you need.

inigoelv
Creator
Creator
Author

Thanks krishnamoorthy, but i have a personal edition of qlikview and I can not open it.

Could you explain the formulas directly?

Thanks in advance,

nagaiank
Specialist III
Specialist III

The script used is given below:

Then create a pivot table chart with Waste and Month as dimensions and Sum(DailyWaste) as expresion to get the result table you want to generate.

SET ThousandSep=',';

SET DecimalSep='.';

SET MoneyThousandSep=',';

SET MoneyDecimalSep='.';

SET MoneyFormat='$#,##0.00;($#,##0.00)';

SET TimeFormat='h:mm:ss TT';

SET DateFormat='D/M/YYYY';

SET TimestampFormat='D/M/YYYY h:mm:ss[.fff] TT';

SET MonthNames='Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec';

SET DayNames='Mon;Tue;Wed;Thu;Fri;Sat;Sun';

Data:

LOAD *

     , [Quantity Ton] / DayCount as DailyQty;

LOAD *

     , [Final date of storage] - [Initial date of storage] + 1 as DayCount;

LOAD * Inline [

Waste,Quantity Ton,Initial date of storage,Final date of storage

A,10,01/01/2012,15/03/2012

B,20,24/02/2012,03/04/2012

];

Temp2:

LOAD Min([Initial date of storage]) as MinDate

   , Max([Final date of storage]) as MaxDate

   Resident Data;

Let vDateMin = Peek('MinDate',-1,Temp2);

Let vDateMax = Peek('MaxDate',-1,Temp2);

Drop Table Temp2;

Calendar:

LOAD $(vDateMin) + RowNo() - 1 AS DateNumber, 

     Date($(vDateMin) + RowNo() - 1) AS Date

     AUTOGENERATE 1 

WHILE $(vDateMin)+IterNo()-1 <= $(vDateMax); 

Outer Join (Data) LOAD Date Resident Calendar;

DROP Table Calendar;

Result:

LOAD *, MonthName(Date) as Month;

LOAD *

     ,If (Date >= [Initial date of storage] and Date <= [Final date of storage], DailyQty, 0) as DailyWaste;

LOAD * Resident Data;

DROP Table Data;

inigoelv
Creator
Creator
Author

Hello:

At the end the solution was:

1) In the script to create a file by moth affected ans waste:

 

LOAD

[Waste],

[Quantity Ton],

[Initial date of storage],

[Final date of storage],

Date(AddMonths(MonthStart ([Initial date of storage]),iterno()-1),'MMMYYYY') as Month

FROM

(
ooxml, embedded labels, header is 3 lines, table is [Waste])while monthstart([Final date of storage]) >= addmonths(monthstart([Initial date of storage]),iterno

()-1);

2) In the espression:

=Sum ([Quantity Ton]/([Final date of storage]-[Initial date of storage]))*(If ([Initial date of storage]>=(MonthStart(Month)), MonthEnd (Month)-[Initial date of storage],
If([Final date of storage]<=(MonthEnd(Month)),[Final date of storage]-MonthStart(Month),
MonthEnd (Month)-MonthStart(Month))))

I hope it will be helpfull.