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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
phoenix
Creator
Creator

Rolling 12 month sum using above() in multi dimensional pivot table

Hello, I have the below table for which I was initially trying to calculate rolling 12 month sum of sales and display at month level.

   

Monthgradesale
1A10
1B20
1C30
2A10
2B20
2C30
3A10
3B20
3C30
4A10
4B20
4C30
5A10
5B20
5C30
6A10
6B20
6C30
7A10
7B20
7C30
8A10
8B20
8C30
9A10
9B20
9C30
10A10
10B20
10C30
11A10
11B20
11C30
12A10
12B20
12C30

Initial output: I got this part correct.

   

Monthsum(aggr(rangesum(above( total sum({<Month=>}sale),0,12)),Month))
160
2120
3180
4240
5300
6360
7420
8480
9540
10600
11660
12720

But when I pull the second dimension into the pivot table, I am not seeing expected results for Rolling 12 months values for the combination of these dimensions.

   

Monthgradesum(aggr(rangesum(above(sum(sale),0,12)),Month,grade))
1A10
1B30
1C60
2A10
2B30
2C60
3A10
3B30
3C60
4A10
4B30
4C60
5A10
5B30
5C60
6A10
6B30
6C60
7A10
7B30
7C60
8A10
8B30
8C60
9A10
9B30
9C60
10A10
10B30
10C60
11A10
11B30
11C60
12A10
12B30
12C60

I expect to see:

   

Monthgradesum(aggr(rangesum(above(sum(sale),0,12)),Month,grade))
1A10
1B20
1C30
2A20
2B40
2C60
3A30
3B60
3C90

Any suggestions. I am not sure if I am doing this right. maybe above() is not the right function here.

I could do it longitudinal like this, which would give right results, but there are many such combination of dimensions in the actual data to do it this way.

   

Monthsum(aggr(rangesum(above( total sum({<Month=,grade={'A'}>}sale),0,12)),Month))sum(aggr(rangesum(above( total sum({<Month=,grade={'B'}>}sale),0,12)),Month))sum(aggr(rangesum(above( total sum({<Month=,grade={'C'}>}sale),0,12)),Month))
1102030
2204060
3306090
44080120
550100150
660120180
770140210
880160240
990180270
10100200300
11110220330
12120240360
12 Replies
phoenix
Creator
Creator
Author

I have these two tables:

LINE_ITEMS1:
Load * Inline [
Account, grade, range
1, A, 10-20
2, A, 20-30
3, A, 10-20
4, B, 30-40
5, B, 30-40
]
;

LINE_ITEMS2:
LOAD * Inline [
Month, Account, loss
1, 1, 0
2, 1, 0
3, 1, 0
4, 1, 100
5, 1, 0
1, 2, 0
2, 2, 0
3, 2, 0
4, 2, 0
5, 2, 0
6, 2, 0
7, 2, 0
8, 2, 0
9, 2, 0
10, 2, 22
11, 2, 0
12, 2, 0
1, 3, 0
2, 3, 0
3, 3, 0
4, 3, 0
5, 3, 0
6, 3, 0
7, 3, 0
8, 3, 0
9, 3, 0
10, 3, 50
11, 3, 0
12, 3, 0
1, 4, 0
2, 4, 0
3, 4, 0
4, 4, 0
5, 4, 0
6, 4, 0
7, 4, 0
8, 4, 0
9, 4, 0
10, 4, 11
11, 4, 0
12, 4, 0
1, 5, 0
2, 5, 0
3, 5, 0
4, 5, 0
5, 5, 0
6, 5, 0
7, 5, 0
8, 5, 0
9, 5, 0
10, 5, 200
11, 5, 0
12, 5, 0

]
;

I want to calculate rolling 12 month loss for each grade and range combination for each month.

desired result:

   

Monthgraderangerolling_12_loss
1A10-200
1A20-300
1B30-400
2A10-200
2A20-300
2B30-400
3A10-200
3A20-300
3B30-400
4A10-20100
4A20-300
4B30-400
5A10-200
5A20-300
5B30-400
6A10-200
6A20-300
6B30-400
7A10-200
7A20-300
7B30-400
8A10-200
8A20-300
8B30-400
9A10-200
9A20-300
9B30-400
10A10-20150
10A20-3022
10B30-40211
11A10-20150
11A20-3022
11B30-40211
12A10-20150
12A20-3022
12B30-40211

 

any suggestions?

Thanks

prat1507
Specialist
Specialist

I didn't get the logic, how come 12 A and 12 B are populated, while others are not. Please explain the logic.

Regards
Pratyush

phoenix
Creator
Creator
Author

I am sorry , yes 5 - A - 10-20, 6 - A - 10-20 .... should also be populated.