Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
thanhphongle
Creator II
Creator II

Accumulation consumptions group by Material_no, Year, Month in script

Hello together

 

how can I accumulate my consumption by Material_No, Calendar Year and Calendar Month in the script??

The result should look like in the Column "Expected_Accumulation_Consumption"

Material_NoCalendar YearCalendar MonthCalendar DateConsumption Quantity
10012020July31.07.20200
10012020August31.08.2020-2
10012020September30.09.20200
10012020October31.10.2020-2
10012020November30.11.20200
10012020December31.12.20200
10012021January31.01.2021-2
10012021February28.02.2021-4
10012021March31.03.2021-10
10022020July31.07.20200
10022020August31.08.2020-6
10022020September30.09.2020-2
10022020October31.10.2020-14
10022020November30.11.2020-5
10022020December31.12.2020-1
10022021January31.01.2021-1
10022021February28.02.2021-4
10022021March31.03.2021-9

 

The goal is to have an additional Field which should look like this

Expected_Accumulation_Consumption
0
-2
-2
-4
-4
-4
-2
-6
-16
0
-6
-8
-22
-27
-28
-1
-5
-14

Hope someone can help me out here.

Thank you

Labels (1)
1 Solution

Accepted Solutions
MayilVahanan

Hi @thanhphongle 

In script, try like below

LOAD *, If(Material_No = Peek(Material_No) and CalendarYear = Peek(CalendarYear),ConsumptionQuantity+Peek(AccConsumptionQuantity), ConsumptionQuantity) as AccConsumptionQuantity INLINE [
Material_No, CalendarYear, Calendar Month, Calendar Date, ConsumptionQuantity
1001, 2020, July, 31.07.2020, 0
1001, 2020, August, 31.08.2020, -2
1001, 2020, September, 30.09.2020, 0
1001, 2020, October, 31.10.2020, -2
1001, 2020, November, 30.11.2020, 0
1001, 2020, December, 31.12.2020, 0
1001, 2021, January, 31.01.2021, -2
1001, 2021, February, 28.02.2021, -4
1001, 2021, March, 31.03.2021, -10
1002, 2020, July, 31.07.2020, 0
1002, 2020, August, 31.08.2020, -6
1002, 2020, September, 30.09.2020, -2
1002, 2020, October, 31.10.2020, -14
1002, 2020, November, 30.11.2020, -5
1002, 2020, December, 31.12.2020, -1
1002, 2021, January, 31.01.2021, -1
1002, 2021, February, 28.02.2021, -4
1002, 2021, March, 31.03.2021, -9
];

Hope ur Materialno & year are in ascending order, if not , u need to use order by.

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

6 Replies
edwin
Master II
Master II

theres a lot of discussions on accumulation, Kush has a great example,

https://community.qlik.com/t5/QlikView-App-Dev/Hot-to-get-the-full-accumulation-when-selection-a-fie...

if this does not apply to you just look it 

MayilVahanan

Hi @thanhphongle 

In script, try like below

LOAD *, If(Material_No = Peek(Material_No) and CalendarYear = Peek(CalendarYear),ConsumptionQuantity+Peek(AccConsumptionQuantity), ConsumptionQuantity) as AccConsumptionQuantity INLINE [
Material_No, CalendarYear, Calendar Month, Calendar Date, ConsumptionQuantity
1001, 2020, July, 31.07.2020, 0
1001, 2020, August, 31.08.2020, -2
1001, 2020, September, 30.09.2020, 0
1001, 2020, October, 31.10.2020, -2
1001, 2020, November, 30.11.2020, 0
1001, 2020, December, 31.12.2020, 0
1001, 2021, January, 31.01.2021, -2
1001, 2021, February, 28.02.2021, -4
1001, 2021, March, 31.03.2021, -10
1002, 2020, July, 31.07.2020, 0
1002, 2020, August, 31.08.2020, -6
1002, 2020, September, 30.09.2020, -2
1002, 2020, October, 31.10.2020, -14
1002, 2020, November, 30.11.2020, -5
1002, 2020, December, 31.12.2020, -1
1002, 2021, January, 31.01.2021, -1
1002, 2021, February, 28.02.2021, -4
1002, 2021, March, 31.03.2021, -9
];

Hope ur Materialno & year are in ascending order, if not , u need to use order by.

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
thanhphongle
Creator II
Creator II
Author

Hello @MayilVahanan ,

 

thank you for your help.

In your solution I dont have the field Peek(AccConsumptionQuantity).

In the table I provided the field "Expected_Accumulation_Consumption" was just an example how the values should look like.

Do you have another solution ?

Thank you in advance

MayilVahanan

Hi @thanhphongle 

AccConsumptionQuantity  is the new field , not from ur data.. 

Below are ur fields..

Material_No, CalendarYear, Calendar Month, Calendar Date, ConsumptionQuantity.

Please look the logic.

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
thanhphongle
Creator II
Creator II
Author

It works, perfect. Thank you so much!!!

MayilVahanan

You're welcome

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.