Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
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
1 Solution

Accepted Solutions
prat1507
Specialist
Specialist

Hi Siva

PFA the .qvw for your desired result.

Regards
Pratyush

View solution in original post

12 Replies
Not applicable

Try like this by removing grade from Aggr  Calculation

sum(aggr(rangesum(above(sum(sale),0,12)),Month))

phoenix
Creator
Creator
Author

if I remove grade in Aggr, I am getting all 'A's

   

Monthgradesum(aggr(rangesum(above(sum(sale),0,12)),Month))
1A60
2A120
3A180
4A240
5A300
6A360
7A420
8A480
9A540
10A600
11A660
12A720
HirisH_V7
Master
Master

Hi Siva,

Check this

Range sum above 12-250132.PNG

By using,

Sum(sale)*Month

as Expression.

You can Drag the Grade Dimension and place it horizontally to get your required longitude approach.

-Hirish

HirisH
“Aspire to Inspire before we Expire!”
prat1507
Specialist
Specialist

This would only work if your Sales are same throughout the year for each month. What if the Sales are like

1     A     10

1     B     20

1     C     30

1     A     15

1     B     8

1     C     10


Regards
Pratyush

HirisH_V7
Master
Master

I hope Pivot Will automatically Group those Month and Grade that gives you the result.

HirisH
“Aspire to Inspire before we Expire!”
phoenix
Creator
Creator
Author

Exactly, as mentioned by pratyush, this wouldn't work if the values are not in the same pattern.

 

Monthgraderangesale
1A10 to 2010
1B30 to 4020
1C50 to 6030
2A10 to 2012
2B30 to 406
2C50 to 604
3A10 to 2010
3B30 to 4099
3C50 to 6030
4A10 to 206
4B30 to 4066
4C50 to 6030
5A10 to 200
5B30 to 4020
5C50 to 6030
6A10 to 20878
6B30 to 4020
6C50 to 6030
7A10 to 2010
7B30 to 408
7C50 to 6030
8A10 to 2010
8B30 to 400
8C50 to 6030
9A10 to 2010
9B30 to 4022
9C50 to 6066
10A10 to 2010
10B30 to 4064
10C50 to 6030
11A10 to 2010
11B30 to 4035
11C50 to 6030
12A10 to 2077
12B30 to 4020
12C50 to 608
1A20 to 3056
1B40 to 509
1C60 to 7030
2A20 to 3078
2B40 to 5020
2C60 to 7030
3A20 to 305
3B40 to 5020
3C60 to 7078
4A20 to 3010
4B40 to 506
4C60 to 709
5A20 to 303
5B40 to 5020
5C60 to 707
6A20 to 3010
6B40 to 5020
6C60 to 709
7A20 to 3078
7B40 to 5020
7C60 to 7030
8A20 to 305
8B40 to 5020
8C60 to 703
9A20 to 3010
9B40 to 5020
9C60 to 7030
10A20 to 3010
10B40 to 5045
10C60 to 706
11A20 to 3024
11B40 to 5020
11C60 to 705
12A20 to 3010
12B40 to 5085
12C60 to 7030

I am getting this:   

Monthgradesum(sale)*Month
1A66
1B29
1C60
2A180
2B52
2C68

but I expect to see:

   

Monthgradesum(sale)*Month
1A66
1B29
1C60
2A156
2B55
2C94
prat1507
Specialist
Specialist

Hi Siva

PFA the .qvw for your desired result.

Regards
Pratyush

prat1507
Specialist
Specialist

Hi Siva

Did you check my solution, is it not working for you? Please let me know if that is the case.

Regards

Pratyush

phoenix
Creator
Creator
Author

It's working, that is what I need. Thanks for your help Pratyush. So the logic here is to create a cross join? Could you help me understand the logic?