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

Load script doubt

Hello everyone,

I have data like shown below:

moporder
3/1/201210
4/1/201235
5/1/201263
6/1/201280
7/1/2012120
8/1/2012200
9/1/2012390
10/1/2012638
11/1/20121250
12/1/20122599
1/1/20133200
2/1/20134320
3/1/20137980

But i want change like below in my load script:

mopwithinmonth1month2month3month4month5month6month>6 and <=12month
3/1/20121035638012020039019987
4/1/201235638012020039063819349
5/1/20126380120200390638125018099
6/1/2012801202003906381250259915500
7/1/201212020039063812502599320012300
8/1/201220039063812502599320043207980
9/1/2012390638125025993200432079800
10/1/20126381250259932004320798000
11/1/201212502599320043207980000
12/1/201225993200432079800000
1/1/201332004320798000000
2/1/201343207980000000
3/1/201379800000000

Could you please advise me

Best,

Robert

22 Replies
SergeyMak
Partner Ambassador
Partner Ambassador

Please try.
[data]:
LOAD mop,
     
order
FROM
[http://community.qlik.com/thread/141358]
(
html, codepage is 1252, embedded labels, table is @1)

;


NoConcatenate
data1:
LOAD *,
IF(isNULL(Previous(Month5)),0,Previous(Month5)) AS Month6;
LOAD *,
IF(isNULL(Previous(Month4)),0,Previous(Month4)) AS Month5;
LOAD *,
IF(isNULL(Previous(Month3)),0,Previous(Month3)) AS Month4;
LOAD *,
IF(isNULL(Previous(Month2)),0,Previous(Month2)) AS Month3;
LOAD *,
IF(isNULL(Previous(Month1)),0,Previous(Month1)) AS Month2;
LOAD mop,
order AS withinmonth,
IF(isNULL(Previous(order)),0,Previous(order)) AS Month1;
LOAD *
Resident data
Order by mop desc;

DROP Table data;
 

But You didn't answer how to calculate the last column... It's not clear at the moment.


Regards,
Sergey
Not applicable
Author

Hi,

Many Thanks. this is what i expected, the last column sum of(Month7 to Month 12).

Best,

Robert

SergeyMak
Partner Ambassador
Partner Ambassador

It's still unclear. I tried to sum up the numbers and couldn't get the numbers you have.

Could you give examples? If you need it, sure.

Regards,

Sergey

Regards,
Sergey
Not applicable
Author

mopwithinmonthMonth1Month2Month3Month4Month5Month6
3/1/201210356380120200390
4/1/2012356380120200390638

In order to get >6 and <=12month for  3/1/2012(Mop):

10/1/2012638Month7
11/1/20121250Month8
12/1/20122599Month9
1/1/20133200Month10
2/1/20134320Month11
3/1/20137980Month12
19987>6 and <=12month

In order to get >6 and <=12month for  4/1/2012(Mop):


11/1/20121250Month7
12/1/20122599Month8
1/1/20133200Month9
2/1/20134320Month10
3/1/20137980Month11
19349>6 and <=12month


Did you get what i mean ?

Best,

Robert

SergeyMak
Partner Ambassador
Partner Ambassador

Hi,

updated script bellow

[data]:
LOAD mop,
     
order
FROM
[http://community.qlik.com/thread/141358]
(
html, codepage is 1252, embedded labels, table is @1)

;


NoConcatenate
data1:
LOAD*,
IF(isNull(Peek('sum')),0,Previous(Month6)+Peek('sum')) AS [sum];
LOAD *,
IF(isNULL(Previous(Month5)),0,Previous(Month5)) AS Month6;
LOAD *,
IF(isNULL(Previous(Month4)),0,Previous(Month4)) AS Month5;
LOAD *,
IF(isNULL(Previous(Month3)),0,Previous(Month3)) AS Month4;
LOAD *,
IF(isNULL(Previous(Month2)),0,Previous(Month2)) AS Month3;
LOAD *,
IF(isNULL(Previous(Month1)),0,Previous(Month1)) AS Month2;
LOAD mop,
order AS withinmonth,
IF(isNULL(Previous(order)),0,Previous(order)) AS Month1;
LOAD *
Resident data
Order by mop desc;

DROP Table data;


Regards,

Sergey

Regards,
Sergey
Not applicable
Author

Hi,

Let me clearly explain my logic for last column:

For each mop, I want to calculate (withinmonth, Month 1 ... Month 6)  but for last column that is what i mentioned >6 and <=12month That is suppose to be Month12.  The metrics calculation would be cumulative sum of( Month7,Month8,Month9,Month10,Month11,Month12).

In my data model, i no need to calculate Month7,Month8,Month9,Month10,Month11,Month12  but i want sum cumulative of (Month 7 to Month 12).

for 3/1/2012 -mop below is the value for month 7 to Month 12. if you sum all the i can get the Month 12 .. 

10/1/2012638Month7
11/1/20121250Month8
12/1/20122599Month9
1/1/20133200Month10
2/1/20134320Month11
3/1/20137980Month12

Answer would be for last column of 3/1/2012  - 19987

My sincere apologizes for my previous explanation was not clear for you.

Best,

Robert

SergeyMak
Partner Ambassador
Partner Ambassador

I have exactly same result as you need

PFA

Regards,
Sergey
Not applicable
Author

Many Thanks

Not applicable
Author

Hi Sergey Makushinsky,

Many Thanks for your solution. its really helps me for one of my vital report.

Best,

Robert

SergeyMak
Partner Ambassador
Partner Ambassador

Hi Robert,

No worries.

I just have to add that it's better for you to follow this thread for the future

Peek() vs Previous() – When to Use Each

As suggested by sujeetsingh

Regards,

Sergey

Regards,
Sergey